KeshavSoft Β· Browser DOM Runtime

Render JSON-driven UI into the browser.

A practical guide to json-renderers β€” the runtime that coordinates UI-spec generation, DOM creation, and mounting rendered components into a page.

1. What is json-renderers?

json-renderers is the browser runtime layer in the KeshavSoft declarative UI ecosystem. It accepts render configuration, obtains a JSON description of the requested component, asks @keshavsoft/json-to-tag to create DOM nodes, and mounts the result in the requested browser container.

It is an orchestration layer rather than the specification compiler itself. The component structure is prepared upstream by json-renderers-build; actual element construction is delegated to @keshavsoft/json-to-tag.

InputData + options

Rows, option values, component type, target element ID, and optional columns.

CoordinationBuild the UI spec

The builder assembles the declarative JSON structure for the selected component.

OutputMounted DOM

Real browser elements appear inside the target container.

Key distinctionjson-renderers does not hand-code each table or dropdown DOM tree. It coordinates the pipeline that converts a declarative specification into mounted browser elements.

2. A simple story everyone can understand

Imagine we are building a house. The same idea helps explain how a UI becomes real HTML on a webpage.

1 Β· The architectjson-renderers-build

The architect prepares a blueprint. Here, it prepares the JSON structure in the format that the next tool expects.

2 Β· The construction workerjson-to-tag

The worker reads the blueprint and builds the actual parts. Here, it converts the JSON specification into real HTML DOM elements.

3 Β· The site managerjson-renderers

The manager takes the built parts to the right place. Here, it mounts the created elements inside the target container on the webpage.

Example: displaying a student table

  1. We provide student data.
    For example: student names and their cities, plus the ID of the HTML container.
  2. The architect prepares the blueprint.
    json-renderers-build produces a JSON specification describing the table.
  3. The construction worker builds the table elements.
    json-to-tag reads that specification and creates the HTML DOM elements.
  4. The site manager puts the table in place.
    json-renderers mounts the result inside the target HTML container, so the user can see the table.
Easy sentence to rememberjson-renderers-build prepares the blueprint, json-to-tag builds the actual DOM elements, and json-renderers places them on the webpage.

3. Architecture and rendering pipeline

The README describes the flow from application inputs to the final browser DOM as a staged pipeline:

Step 01Application data

Pass a component type, data, columns, and target HTML ID.

Step 02json-renderers-build

Builds a declarative JSON specification for the component.

Step 03json-to-tag

Converts the specification into browser DOM nodes.

Step 04json-renderers

Mounts the result into the specified container.

  1. The application calls the render function.
    The configuration includes values such as type, targetHtmlId, data, and optionally columns.
  2. The builder prepares the component specification.
    The json-renderers-build package combines the component blueprint with the supplied data and returns a JSON spec.
  3. The JSON spec is converted into DOM.
    @keshavsoft/json-to-tag constructs the relevant HTML elements from that specification.
  4. The runtime mounts the generated elements.
    The renderer resolves the destination element and applies its mounting behavior.
Remember this for a technical explanationjson-renderers-build prepares the structure, json-to-tag creates the elements, and json-renderers coordinates and mounts the result.

3. Main features

Table rendering

Creates a table with headers and rows from the supplied data. The README documents Bootstrap table classes.

Select dropdown

Builds a select element and populates it with the provided options.

Existing select options

Can add option elements to an already-existing select element.

Flexible mounting

Supports default content replacement and a prepend option.

Browser global

The README documents a browser bundle that registers under window.ks.jsonRenderers.

ES module / npm

Can be used through the package or a browser ES module bundle.

Documented renderer types: table, select, and selectOptionsOnly.

4. Installation

Option A β€” npm

Install the package in your JavaScript project:

Terminal
npm install json-renderers

Then import the default render function in your JavaScript module:

JavaScript
import render from "json-renderers";

Option B β€” browser ES module bundle

The README documents loading the v13 bundle from jsDelivr:

HTML
<script type="module" src="https://cdn.jsdelivr.net/gh/keshavsoft/json-renderers@main/docs/dist/v13/min.js"></script>

According to the README, the browser bundle registers a global API at window.ks.jsonRenderers, including renderToDom.

Choose one setupUse npm imports in a bundled application, or load the documented browser module in a page. Check the live README before publishing a project to confirm the currently recommended bundle/version.

5. Quick start examples

Each example needs a destination element in the HTML and a call to render with the corresponding options. The snippets below follow the examples documented in the repository README.

Example A β€” render a table

HTML
<div id="table-container"></div>
JavaScript
import render from "json-renderers";

const records = [
  { id: 101, name: "Alpha Enterprise", city: "Hyderabad" },
  { id: 102, name: "Beta Logistics", city: "Bengaluru" }
];

render({
  type: "table",
  targetHtmlId: "table-container",
  data: records,
  columns: ["Name", "City"]
});

Expected result: a table is mounted inside the #table-container element, showing the selected columns and data rows.

Example B β€” render a select dropdown

HTML
<div id="dropdown-container"></div>
JavaScript
import render from "json-renderers";

render({
  type: "select",
  targetHtmlId: "dropdown-container",
  data: ["Account Receivable", "Account Payable", "Sales Revenue"]
});

Expected result: a select element is generated with the supplied values as options.

Example C β€” add options to an existing select

HTML
<select id="user-role-select" class="form-select">
  <option value="" disabled selected>Select Role...</option>
</select>
JavaScript
import render from "json-renderers";

render({
  type: "selectOptionsOnly",
  targetHtmlId: "user-role-select",
  data: ["Administrator", "Editor", "Viewer"]
});

Expected result: options for Administrator, Editor, and Viewer are added to the existing select control.

6. API reference

The README documents the default export as a render function receiving one options object.

Function signature
render({
  type = "table",
  targetHtmlId,
  data,
  columns,
  appendPosition,
  showLog = false
});
Parameter Type Default Purpose
type String "table" Selects the renderer: table, select, or selectOptionsOnly.
targetHtmlId String Not set ID of the destination element resolved through document.getElementById(...).
data Array [] Row objects for a table; string values for select/dropdown option renderers.
columns Array Not set Table column headers; the README describes strings or objects such as { title: "Name" }.
appendPosition String Not set Use "prepend" to prepend content. Otherwise, the documented behavior replaces existing container content.
showLog Boolean false Enables debug logging during rendering.

Return value

The README describes the return value as an HTMLElement representing the mounted DOM container.

Usage checkMake sure the element named by targetHtmlId already exists in the page before calling the render function. The parameter is an element ID, not a CSS selector.

7. How it differs from json-renderers-build

These packages work together, but they have different responsibilities.

Specification stage

json-renderers-build β†—

  • Prepares the JSON component specification.
  • Combines component blueprints with input data and options.
  • Produces a declarative specification, rather than directly mounting DOM.
Browser runtime stage

json-renderers

  • Coordinates the full render path.
  • Passes the spec to json-to-tag for element construction.
  • Mounts the resulting nodes into the target browser container.
Aspect json-renderers-build json-renderers
Primary job Build UI specification Coordinate and mount rendered UI
Output / result Declarative JSON spec Rendered DOM mounted in a page
DOM mounting Not its main responsibility Core runtime responsibility
Typical use Build custom or reusable specifications Render components in browser applications

8. Project structure

The README describes the repository as organized around source runtime code, browser documentation/build output, and runnable samples.

Repository map (from README)
json-renderers/
β”œβ”€β”€ docs/                     # Documentation and distribution
β”‚   β”œβ”€β”€ dist/                 # Built browser bundles
β”‚   β”‚   β”œβ”€β”€ min.js
β”‚   β”‚   └── v13/min.js
β”‚   └── index.html            # Docs and interactive workbench
β”œβ”€β”€ samples/                  # Browser examples
β”‚   β”œβ”€β”€ table/
β”‚   β”œβ”€β”€ select/
β”‚   └── selectOptionsOnly/
β”œβ”€β”€ src/                      # Source code
β”‚   β”œβ”€β”€ index.js              # Package entry
β”‚   └── v13/                  # Runtime implementation
β”‚       β”œβ”€β”€ buildSpec/
β”‚       β”œβ”€β”€ meta.js
β”‚       β”œβ”€β”€ registerGlobal.js
β”‚       └── index.js
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
└── README.md

File paths and bundle names can change over time; use the repository’s current default branch as the source of truth.

9. Development and build

To run the project locally, the README documents the following commands:

Terminal
# Install dependencies
npm install

# Start the Vite development server
npm run dev

# Build production bundles
npm run build

Use npm run dev to work with the project locally, then npm run build to build the production bundles described in the README. Consult package.json for the exact scripts in the current checkout.

Practical troubleshooting

  • Nothing renders: confirm the target container exists and that targetHtmlId matches its ID exactly.
  • Wrong component appears: check the type value and the shape of data.
  • Table columns are missing: verify the columns array matches the intended record properties/headers.
  • Unexpectedly replaced content: review appendPosition; the README describes replacement as the default and prepend as an alternative.

10. Official links and references

This guide is based on the repository’s README and documentation links available when the page was prepared. Check these sources for the latest implementation details.

Select dropdown guide

Select component guide β†—

Builder repository

json-renderers-build β†—

DOM conversion package

json-to-tag β†—

License The README identifies the project as MIT-licensed. See the repository’s current LICENSE file for the license text.

Explore More Documentation

Looking for a quick conceptual model or interactive live playground?