JSON Layout API Reference

Complete technical reference for the RSL JSON Layout system

Table of Contents

Overview

The RSL JSON Layout system provides declarative, JSON-driven layout rendering with two API versions:

  1. V1 API - Basic JSON-to-DOM rendering with HTML content
  2. V2 API - Semantic content types, template system, and 50+ component renderers

Recommendation

Use V2 for new projects. V1 is fully supported for backward compatibility.

Quick Start (V2)

Basic Setup • HTML
<!-- Include required files -->
<link rel="stylesheet" href="styles/grid.css">
<link rel="stylesheet" href="styles/cards.css">
<script src="javascript/layout.js"></script>
<script src="javascript/layout-json-engine-v2.js"></script>

<div id="app"></div>

<script>
RSL.JSONLayout.renderLayout('#app', {
  version: 2,
  layoutId: "my-layout",
  breakpoints: { xs: 1, md: 2, lg: 3 },
  gap: "1.5rem",
  items: [
    {
      content: {
        type: "card",
        title: "Welcome",
        body: "This is a semantic card component.",
        button: { text: "Learn More", variant: "primary" }
      }
    }
  ]
});
</script>

V2 Content Types

Layout Types

TypeDescription
cardCard component with title, body, image, buttons
gridNested grid layout
balancedMasonry-style balanced layout
dividerHorizontal divider line
spacerVertical spacing

Typography Types

TypeDescription
headingH1-H6 headings with level option
paragraphText paragraph
textPlain text content
listOrdered or unordered lists
badgeInline badge/tag

Interactive Types

TypeDescription
buttonButton with variants and icons
linkHyperlink
accordionExpandable accordion panels
tabsTabbed content interface
modalModal dialog
selectDropdown select
tooltipTooltip on hover
popoverPopover panel
toastToast notification

Media Types

TypeDescription
imageImage with alt text
thumbnailImage card with overlay
galleryImage gallery with lightbox
carouselImage slideshow
video-playerVideo player component
iframeEmbedded iframe
iconFontAwesome icon

Navigation Types

TypeDescription
navbarNavigation bar
breadcrumbBreadcrumb navigation
paginationPage navigation
sidebarSidebar layout
offcanvasSlide-out panel

Data Display Types

TypeDescription
tableData table
smart-tableAdvanced table with sorting/filtering
chartSVG charts (bar, line, pie, etc.)
kpiKPI dashboard cards
ganttGantt chart
progressProgress bar
calendarFull calendar component

Form Types

TypeDescription
formForm container
datepickerDate picker
timepickerTime picker
filterFilter controls
star-ratingStar rating input

Feedback Types

TypeDescription
alertAlert message
inlayAlertInline contextual alert
skeletonLoading placeholder
announcementsAnnouncement bar

Specialty Types

TypeDescription
heroHero section
testimonialTestimonial card
pricing-tablePricing comparison
iconpickerIcon selection

V1 Types (Backward Compatible)

TypeDescription
htmlRaw HTML content
slotTemplate slot reference
componentRSL component reference

Template System

The template system renders arrays of data with {{variable}} interpolation.

Template Example • JavaScript
const products = [
  { name: "Product 1", price: "99", image: "img1.jpg" },
  { name: "Product 2", price: "149", image: "img2.jpg" },
  { name: "Product 3", price: "199", image: "img3.jpg" }
];

RSL.JSONLayout.renderLayout('#container', {
  version: 2,
  layoutId: "products",
  breakpoints: { xs: 1, md: 2, lg: 3 },
  template: {
    data: products,
    item: {
      content: {
        type: "card",
        image: "{{image}}",
        title: "{{name}}",
        price: "${{price}}",
        button: { text: "Buy Now", variant: "primary" }
      }
    }
  }
});

Interpolation Patterns

Interpolation works on any string value, including nested properties and classes.

API Methods

RSL.JSONLayout.renderLayout(container, config)

Renders a layout from JSON configuration.

Parameters:

container (string | HTMLElement)
Container selector or element
config (Object)
JSON layout configuration

Returns:

HTMLElement - The created layout element

RSL.JSONLayout.convertHTMLtoJSON(source, options)

Converts existing HTML to JSON configuration.

Parameters:

source (string | HTMLElement)
HTML string, selector, or element
options (Object)
Optional settings: version, layoutId, preserveComments

Returns:

Object - JSON configuration

Usage Examples • JavaScript
// From HTML string
const config = RSL.JSONLayout.convertHTMLtoJSON('<div class="slot-layout">...</div>');

// From selector
const config = RSL.JSONLayout.convertHTMLtoJSON('#my-container');

// From element
const config = RSL.JSONLayout.convertHTMLtoJSON(document.body);
RSL.JSONLayout.validateSchema(config)

Validates a JSON layout configuration.

Parameters:

config (Object)
Configuration to validate

Returns:

Object - { valid: boolean, errors: string[], warnings: string[] }

RSL.JSONLayout.updateLayoutFromJSON(container, config)

Updates an existing layout (diff-based, preserves DOM where possible).

Parameters:

container (string | HTMLElement)
Container with layout
config (Object)
New configuration

Returns:

Object - { added, updated, removed } stats

Configuration Schema

V2 Layout Configuration

Schema Definition • TypeScript
{
  version: 2,                     // Schema version (required)
  layoutId: string,               // Unique ID (required)
  breakpoints: {                  // Column counts per breakpoint
    xs?: number,                  // Extra small (<480px)
    sm?: number,                  // Small (>=480px)
    md?: number,                  // Medium (>=768px)
    lg?: number,                  // Large (>=1024px)
    xl?: number,                  // Extra large (>=1280px)
    xxl?: number                  // Extra extra large (>=1600px)
  },
  gap?: string,                   // Gap between items (e.g., "1.5rem")
  pageMode?: boolean,             // Full page rendering mode
  items?: LayoutItem[],           // Array of layout items
  template?: {                    // Template system config
    data: any[],                  // Array of data objects
    item: LayoutItem              // Template for each item
  }
}

Layout Item

Item Schema • TypeScript
{
  id?: string,                    // Unique ID
  classes?: string[],             // CSS classes
  order?: number,                 // Flex order
  visible?: boolean,              // Visibility (default: true)
  span?: {                        // Column span per breakpoint
    xs?: number,
    sm?: number,
    md?: number,
    lg?: number
  },
  content?: ContentConfig,        // Item content
  style?: Record<string, string>, // Inline styles
  data?: Record<string, string>   // Data attributes
}

Content Type Examples

Card

Card Configuration • JavaScript
{
  type: "card",
  image: "photo.jpg",
  imageAlt: "Description",
  title: "Card Title",
  titleIcon: "fa fa-star",       // Icon before title
  subtitle: "Subtitle text",
  body: "Card body content",
  price: "$99",
  button: { text: "Action", variant: "primary", href: "#" },
  buttons: [                      // Multiple buttons
    { text: "Primary", variant: "primary" },
    { text: "Secondary", variant: "secondary" }
  ]
}

Accordion

Accordion Configuration • JavaScript
{
  type: "accordion",
  variant: "classic",             // "classic" or "modern"
  allowMultiple: false,
  items: [
    { title: "Section 1", content: "Content 1", open: true },
    { title: "Section 2", content: "Content 2" }
  ]
}

Tabs

Tabs Configuration • JavaScript
{
  type: "tabs",
  variant: "horizontal",          // "horizontal" or "vertical"
  tabs: [
    { id: "tab1", label: "Tab 1", content: "Content 1", active: true },
    { id: "tab2", label: "Tab 2", content: "Content 2" }
  ]
}

Table

Table Configuration • JavaScript
{
  type: "table",
  headers: ["Name", "Email", "Role"],
  rows: [
    ["John Doe", "john@example.com", "Admin"],
    ["Jane Smith", "jane@example.com", "User"]
  ],
  striped: true,
  hoverable: true
}

Chart

Chart Configuration • JavaScript
{
  type: "chart",
  chartType: "bar",               // bar, line, area, pie, doughnut
  data: [
    { label: "Jan", value: 100 },
    { label: "Feb", value: 150 },
    { label: "Mar", value: 120 }
  ],
  colorScheme: "primary",
  showLegend: true,
  showGrid: true
}

Gallery

Gallery Configuration • JavaScript
{
  type: "gallery",
  images: [
    { src: "img1.jpg", alt: "Image 1", caption: "Caption 1" },
    { src: "img2.jpg", alt: "Image 2", caption: "Caption 2" }
  ],
  columns: { xs: 2, md: 3, lg: 4 },
  gap: "1rem",
  lightbox: true
}

Hero

Hero Configuration • JavaScript
{
  type: "hero",
  title: "Welcome",
  subtitle: "Build amazing layouts",
  backgroundImage: "hero.jpg",
  buttons: [
    { text: "Get Started", variant: "primary" },
    { text: "Learn More", variant: "secondary" }
  ],
  centered: true
}

Custom HTML (V1 Style)

Custom HTML • JavaScript
{
  type: "html",
  value: "<div class='custom-widget'><h3>Custom Content</h3><p>Any HTML here</p></div>"
}

State Manager (Optional)

For undo/redo and preset management, include the state manager:

Include State Manager • HTML
<script src="javascript/layout-state-manager.js"></script>
<script src="javascript/layout-control-panel.js"></script>

State Manager API

API Methods • JavaScript
// Save state to history
RSL.StateManager.pushToHistory('Description');

// Undo/Redo
RSL.StateManager.undo();
RSL.StateManager.redo();

// Presets
RSL.StateManager.savePreset('My Layout');
RSL.StateManager.loadPreset('My Layout');
RSL.StateManager.getPresetNames();
RSL.StateManager.deletePreset('My Layout');

// Import/Export
const data = RSL.StateManager.toJSON({ includeSchema: true });
RSL.StateManager.fromJSON(data, { container: '#app' });

Events

Event Listeners • JavaScript
// Layout engine ready
window.addEventListener('rsl:jsonlayout:ready', () => {});

// State changed
window.addEventListener('rsl:statechange', (e) => {
  console.log(e.detail.state);
});

Browser Support