PluginBench
Skill
Official
Pass
Audit score 90

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
Prerequisites
  • Node.js and npm installed
  • Familiarity with json-render specs and tree structures
  • Basic understanding of code generation patterns
Claude Code
Cursor
Windsurf
Cline

How to use codegen

  1. 1.Install the package: npm install @json-render/codegen
  2. 2.Import traversal utilities (traverseSpec, collectUsedComponents, etc.) to analyze specs
  3. 3.Use serialization functions (serializePropValue, serializeProps) to convert values to code strings
  4. 4.Implement a CodeGenerator function that returns an array of GeneratedFile objects
  5. 5.Call your generator with a spec to produce output files

Use cases

Good for
  • 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
Who it's for
  • 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

What is json-render?

json-render is a framework for rendering UI from JSON specifications. @json-render/codegen provides utilities to generate code from those specs.

Can I use this with frameworks other than Next.js?

Yes, the utilities are framework-agnostic. You build a custom generator function that outputs code for your target framework (Remix, Vue, Svelte, etc.).

What does traverseSpec do?

It walks the UI spec tree depth-first, calling a callback for each element so you can inspect or transform the structure.

How do I serialize complex prop values?

Use serializePropValue() for individual values or serializeProps() for entire prop objects; both handle strings, numbers, state references, and nested objects.

Do I need to understand the full json-render ecosystem?

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