codegen▌
vercel-labs/json-render · updated Apr 8, 2026
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.
@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;
}
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★63 reviews- ★★★★★Chaitanya Patil· Dec 28, 2024
We added codegen from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Kwame Sanchez· Dec 24, 2024
codegen has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Valentina Martin· Dec 24, 2024
Useful defaults in codegen — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Lucas Verma· Dec 24, 2024
Solid pick for teams standardizing on skills: codegen is focused, and the summary matches what you get after install.
- ★★★★★Valentina Torres· Dec 20, 2024
codegen reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★Aanya Verma· Dec 16, 2024
codegen fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Ama Choi· Dec 12, 2024
We added codegen from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Arjun Ghosh· Nov 23, 2024
codegen fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.
- ★★★★★Piyush G· Nov 19, 2024
codegen reduced setup friction for our internal harness; good balance of opinion and flexibility.
- ★★★★★William Diallo· Nov 15, 2024
I recommend codegen for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
showing 1-10 of 63