codegen
vercel-labs/json-render
Framework-agnostic code generation utilities for json-render UI trees.
What is codegen?
@json-render/codegen provides utilities to traverse json-render UI specifications, collect metadata (components, state paths, actions), and serialize values for code generation. Use it when building custom code exporters for frameworks like Next.js or Remix, or when you need to programmatically analyze and transform UI specs into generated code.
- Traverse UI specs depth-first to inspect structure and metadata
- Collect all component types, state paths, and action names used in a spec
- Serialize prop values and objects into JSX-compatible code strings
- Escape and format strings safely for code generation
- Build custom code generators that output multiple files from a single spec
How to install codegen
npx skills add https://github.com/vercel-labs/json-render --skill codegen- Node.js and npm installed
- Familiarity with json-render specs and tree structures
- Basic understanding of code generation patterns
How to use codegen
- 1.Install the package: npm install @json-render/codegen
- 2.Import traversal utilities (traverseSpec, collectUsedComponents, etc.) to analyze specs
- 3.Use serialization functions (serializePropValue, serializeProps) to convert values to code strings
- 4.Implement a CodeGenerator function that returns an array of GeneratedFile objects
- 5.Call your generator with a spec to produce output files
Use cases
- Export a json-render UI design to a Next.js or Remix project with generated component files
- Build a visual editor that generates production-ready code from UI trees
- Analyze specs to extract dependencies and generate package.json automatically
- Create framework-specific code exporters (Vue, Svelte, etc.) from json-render specs
- Generate TypeScript types and state management code from UI specifications
- Frontend developers building code generation tools
- Design system maintainers exporting designs to code
- Framework integrators extending json-render to new platforms
- Developers automating UI-to-code workflows
codegen FAQ
json-render is a framework for rendering UI from JSON specifications. @json-render/codegen provides utilities to generate code from those specs.
Yes, the utilities are framework-agnostic. You build a custom generator function that outputs code for your target framework (Remix, Vue, Svelte, etc.).
It walks the UI spec tree depth-first, calling a callback for each element so you can inspect or transform the structure.
Use serializePropValue() for individual values or serializeProps() for entire prop objects; both handle strings, numbers, state references, and nested objects.
Basic familiarity with json-render specs is helpful, but the utilities are designed to be self-contained for code generation tasks.
Full instructions (SKILL.md)
Source of truth, from vercel-labs/json-render.
name: codegen description: Code generation utilities for json-render. Use when generating code from UI specs, building custom code exporters, traversing specs, or serializing props for @json-render/codegen.
@json-render/codegen
Framework-agnostic utilities for generating code from json-render UI trees. Use these to build custom code exporters for Next.js, Remix, or other frameworks.
Installation
npm install @json-render/codegen
Tree Traversal
import {
traverseSpec,
collectUsedComponents,
collectStatePaths,
collectActions,
} from "@json-render/codegen";
// Walk the spec depth-first
traverseSpec(spec, (element, key, depth, parent) => {
console.log(`${" ".repeat(depth * 2)}${key}: ${element.type}`);
});
// Get all component types used
const components = collectUsedComponents(spec);
// Set { "Card", "Metric", "Button" }
// Get all state paths referenced
const statePaths = collectStatePaths(spec);
// Set { "analytics/revenue", "user/name" }
// Get all action names
const actions = collectActions(spec);
// Set { "submit_form", "refresh_data" }
Serialization
import {
serializePropValue,
serializeProps,
escapeString,
type SerializeOptions,
} from "@json-render/codegen";
// Serialize a single value
serializePropValue("hello");
// { value: '"hello"', needsBraces: false }
serializePropValue({ $state: "/user/name" });
// { value: '{ $state: "/user/name" }', needsBraces: true }
// Serialize props for JSX
serializeProps({ title: "Dashboard", columns: 3, disabled: true });
// 'title="Dashboard" columns={3} disabled'
// Escape strings for code
escapeString('hello "world"');
// 'hello \"world\"'
SerializeOptions
interface SerializeOptions {
quotes?: "single" | "double";
indent?: number;
}
Types
import type { GeneratedFile, CodeGenerator } from "@json-render/codegen";
const myGenerator: CodeGenerator = {
generate(spec) {
return [
{ path: "package.json", content: "..." },
{ path: "app/page.tsx", content: "..." },
];
},
};
Building a Custom Generator
import {
collectUsedComponents,
collectStatePaths,
traverseSpec,
serializeProps,
type GeneratedFile,
} from "@json-render/codegen";
import type { Spec } from "@json-render/core";
export function generateNextJSProject(spec: Spec): GeneratedFile[] {
const files: GeneratedFile[] = [];
const components = collectUsedComponents(spec);
// Generate package.json, component files, main page...
return files;
}
Related skills
More from vercel-labs/json-render and the wider catalog.

core
Core schema, catalog, and AI prompt generation for json-render specs and UI composition.

devtools
Drop-in inspector panel for json-render apps with spec tree, state editor, action timeline, and stream monitoring.

directives
Pre-built custom directives for json-render — formatting, math, string manipulation, and i18n.

image
Convert JSON specs to SVG and PNG images using Satori for OG images and social cards.

ink
Ink terminal renderer for json-render that turns JSON specs into interactive terminal UIs. Use when working with @json-render/ink, building terminal UIs from JSON, creating terminal component catalogs, or rendering AI-generated specs in the terminal.

jotai
Jotai adapter for json-render's StateStore interface. Use when integrating json-render with Jotai for state management via @json-render/jotai.