Skip to content

About

The Generative UI framework

Resources

Contributing

Stars

20.0k stars

Watchers

52 watching

Forks

Latest commit

 

History

272 Commits

Folders and files

Repository files navigation

json-render

Vercel Labs Product npm version: @json-render/core License: Apache-2.0 npm downloads per month: @json-render/core

json-render is a framework for generative UI. AI generates interfaces from natural language, and json-render renders them from JSON specs constrained to a catalog of components and actions you define. The catalog keeps generated UI predictable and type-safe, with no arbitrary code execution.

json-render does not call a model itself. Generate specs with any AI SDK and stream them into a renderer; SpecStream renders the UI progressively while the model is still responding. The same catalog works across React, Vue, Svelte, Solid, and React Native.

Installation

Install the core package with a renderer using npm:

$ npm install @json-render/core @json-render/react

The React renderer requires React 19 and Zod 4. Add the Vercel AI SDK (ai) when you generate specs with a model. See installation for the packages and peer dependencies of each target.

Packages

Each renderer turns a spec constrained to a catalog into output for one platform or format. Every public package is published under the @json-render scope:

Package Description
@json-render/core Schemas, catalogs, AI prompts, dynamic props, and SpecStream utilities
@json-render/react React renderer, contexts, and hooks
@json-render/vue Vue 3 renderer, composables, and providers
@json-render/svelte Svelte 5 renderer with runes-based reactivity
@json-render/solid SolidJS renderer with fine-grained reactive contexts
@json-render/shadcn 36 prebuilt shadcn/ui components (Radix UI + Tailwind CSS)
@json-render/shadcn-svelte 36 prebuilt shadcn-svelte components (Svelte 5 + Tailwind CSS)
@json-render/react-three-fiber React Three Fiber renderer for 3D scenes, including Gaussian splatting
@json-render/react-native React Native renderer with standard mobile components
@json-render/next Next.js renderer for full apps with routes, layouts, SSR, and metadata
@json-render/tanstack-start TanStack Start renderer for full apps with routes, layouts, SSR, and head metadata
@json-render/remotion Remotion video renderer with a timeline schema
@json-render/react-pdf React PDF renderer for PDF documents
@json-render/react-email React Email renderer for HTML and plain-text emails
@json-render/chat Chat SDK renderer for Slack, Teams, Discord, and Google Chat cards
@json-render/ink Ink terminal renderer with built-in components for interactive TUIs
@json-render/image Image renderer for SVG and PNG output via Satori (OG images, social cards)
@json-render/directives Prebuilt directives: $format, $math, $concat, $count, $truncate, $pluralize, $join, and $t (i18n)
@json-render/codegen Utilities for generating code from json-render UI trees
@json-render/devtools Framework-agnostic devtools core with panel UI, event store, picker, and stream taps
@json-render/devtools-react React adapter for @json-render/devtools with a drop-in <JsonRenderDevtools /> component
@json-render/devtools-vue Vue adapter for @json-render/devtools
@json-render/devtools-svelte Svelte adapter for @json-render/devtools
@json-render/devtools-solid SolidJS adapter for @json-render/devtools
@json-render/redux Redux and Redux Toolkit adapter for StateStore
@json-render/zustand Zustand adapter for StateStore
@json-render/jotai Jotai adapter for StateStore
@json-render/xstate XState Store atom adapter for StateStore
@json-render/mcp MCP Apps integration for Claude, ChatGPT, Cursor, and VS Code
@json-render/yaml YAML wire format with a streaming parser, edit modes, and an AI SDK transform

Build a UI

Define a catalog of the components AI can use (catalog.ts):

import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react/schema";
import { z } from "zod";

export const catalog = defineCatalog(schema, {
  components: {
    Card: {
      props: z.object({ title: z.string() }),
      slots: ["default"],
      description: "Container for grouping content",
    },
    Button: {
      props: z.object({ label: z.string() }),
      description: "Clickable button that emits a press event",
    },
  },
});

Map each catalog type to a component with defineRegistry (registry.tsx):

import { defineRegistry } from "@json-render/react";
import { catalog } from "./catalog";

export const { registry } = defineRegistry(catalog, {
  components: {
    Card: ({ props, children }) => (
      <div className="card">
        <h3>{props.title}</h3>
        {children}
      </div>
    ),
    Button: ({ props, emit }) => (
      <button onClick={() => emit("press")}>{props.label}</button>
    ),
  },
});

AI generates JSON specs like this:

{
  "root": "card-1",
  "elements": {
    "card-1": {
      "type": "Card",
      "props": { "title": "Revenue" },
      "children": ["button-1"]
    },
    "button-1": {
      "type": "Button",
      "props": { "label": "Refresh" },
      "children": []
    }
  }
}

Render the spec:

import { Renderer, type Spec } from "@json-render/react";
import { registry } from "./registry";

export function GeneratedUI({ spec }: { spec: Spec }) {
  return <Renderer spec={spec} registry={registry} />;
}

Add StateProvider, VisibilityProvider, and ActionProvider for data binding, conditional visibility, and actions, as shown in the quick start.

Generate with AI

Create a streaming API route. catalog.prompt() returns a system prompt describing your components, prop schemas, actions, and the spec format:

// app/api/generate/route.ts
import { streamText } from "ai";
import { catalog } from "@/lib/catalog";

export async function POST(req: Request) {
  const { prompt } = await req.json();
  const result = streamText({
    model: "anthropic/claude-haiku-4.5",
    system: catalog.prompt(),
    prompt,
  });
  return result.toTextStreamResponse();
}

On the client, useUIStream sends prompts and builds the spec as chunks arrive:

import { Renderer, useUIStream } from "@json-render/react";
import { registry } from "./registry";

export function GeneratedUI() {
  const { spec, isStreaming, send } = useUIStream({ api: "/api/generate" });

  return (
    <>
      <button disabled={isStreaming} onClick={() => send("Show revenue")}>
        Generate
      </button>
      <Renderer spec={spec} registry={registry} />
    </>
  );
}

Use prebuilt components

@json-render/shadcn provides definitions and matching implementations for 36 shadcn/ui components, so you don't have to build them from scratch:

import { defineCatalog } from "@json-render/core";
import { schema } from "@json-render/react/schema";
import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";

const catalog = defineCatalog(schema, {
  components: {
    Card: shadcnComponentDefinitions.Card,
    Stack: shadcnComponentDefinitions.Stack,
    Heading: shadcnComponentDefinitions.Heading,
    Button: shadcnComponentDefinitions.Button,
  },
  actions: {},
});

Install it alongside @json-render/core and @json-render/react, then register the implementations from @json-render/shadcn under the same names with defineRegistry. Requires Tailwind CSS; see the shadcn API reference.

Documentation

To run the examples locally, install dependencies and start the workspace with pnpm install and pnpm dev. The dev script requires portless; the docs and playground run at http://json-render.localhost:1355.

Contributing

See CONTRIBUTING.md for local development, repository layout, and pull request guidelines. Report bugs in GitHub Issues.

About

The Generative UI framework

Resources

Contributing

Stars

20.0k stars

Watchers

52 watching

Forks

Releases

Packages

Used by

Contributors

Languages