Codegen

by vercel-labsfc2a696a50a3No license18K starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated yesterday

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.

FeaturedInstructions onlySoftware Development
AI-generated overview

Reference for @json-render/codegen utilities that turn json-render UI specs into framework code.

What it does
This skill documents the @json-render/codegen package, a framework-agnostic toolkit for generating code from json-render UI trees. It covers tree traversal helpers that walk a spec and collect used components, state paths, and actions, plus serialization helpers that turn prop values into JSX-ready strings. It also shows the GeneratedFile and CodeGenerator types and sketches how to build a custom exporter for Next.js, Remix, or other frameworks.
When to use it
Use it when generating code from UI specs, building custom code exporters, traversing specs, or serializing props for @json-render/codegen. It suits developers working with json-render UI trees who need traversal or serialization behavior.
Requirements
Requires the @json-render/codegen npm package and the @json-render/core types; examples are TypeScript. Ships no scripts, only instructions.

@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

bash
npm install @json-render/codegen

Tree Traversal

typescript
import {  traverseSpec,  collectUsedComponents,  collectStatePaths,  collectActions,} from "@json-render/codegen";
// Walk the spec depth-firsttraverseSpec(spec, (element, key, depth, parent) => {  console.log(`${" ".repeat(depth * 2)}${key}: ${element.type}`);});
// Get all component types usedconst components = collectUsedComponents(spec);// Set { "Card", "Metric", "Button" }
// Get all state paths referencedconst statePaths = collectStatePaths(spec);// Set { "analytics/revenue", "user/name" }
// Get all action namesconst actions = collectActions(spec);// Set { "submit_form", "refresh_data" }

Serialization

typescript
import {  serializePropValue,  serializeProps,  escapeString,  type SerializeOptions,} from "@json-render/codegen";
// Serialize a single valueserializePropValue("hello");// { value: '"hello"', needsBraces: false }
serializePropValue({ $state: "/user/name" });// { value: '{ $state: "/user/name" }', needsBraces: true }
// Serialize props for JSXserializeProps({ title: "Dashboard", columns: 3, disabled: true });// 'title="Dashboard" columns={3} disabled'
// Escape strings for codeescapeString('hello "world"');// 'hello \"world\"'

SerializeOptions

typescript
interface SerializeOptions {  quotes?: "single" | "double";  indent?: number;}

Types

typescript
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

typescript
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;}

Source and attribution

Source:vercel-labs/json-renderinskills/codegenat commitfc2a696

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal

Codegen Agent Skill | SourceWeft