
JSON Render Directives
OfficialFreePre-built directives for JSON rendering and manipulation.
Free · Opens the source repo
What JSON Render Directives does
The JSON Render Directives skill provides a set of pre-built custom directives designed to enhance the functionality of the @json-render/core library. By integrating these directives into your JSON rendering workflow, you can easily implement features such as formatting, mathematical operations, string manipulation, and internationalization (i18n). This skill is particularly useful for developers working with dynamic data rendering in applications, allowing for more expressive and flexible UI components.
With directives like $format, you can format values according to locale-aware standards, which is essential for applications that cater to a global audience. The $math directive allows you to perform arithmetic operations directly within your JSON specifications, simplifying the handling of numerical data. String operations can be seamlessly managed using directives like $concat, $truncate, and $pluralize, making it easier to manipulate and display text based on varying conditions.
The skill also supports the creation of custom directives through the defineDirective function, enabling developers to extend the capabilities of the library to meet specific application needs. This flexibility is crucial for projects that require tailored solutions beyond the built-in directives. Additionally, the skill's directives compose naturally, allowing for complex operations to be defined in a straightforward manner, enhancing maintainability and readability of your code.
Overall, this skill is aimed at developers who need to streamline their JSON rendering processes while maintaining high levels of customization and performance. It is an essential tool for anyone looking to leverage the power of JSON in their applications effectively.
When to use it
Use this skill when you need to render JSON data dynamically with formatting, calculations, or string manipulations in your application.
When not to use it
This skill may not be suitable for applications that do not utilize JSON rendering or require complex business logic that cannot be expressed through directives.
What you can build with it
Dynamic User Interfaces
Utilize JSON Render Directives to build dynamic user interfaces that require real-time data formatting and calculations.
Internationalized Applications
Implement internationalization in your applications by using the `$t` directive for translation keys and messages.
Data-Driven Reports
Generate data-driven reports that require complex string manipulations and arithmetic operations directly within the JSON specifications.
How to install JSON Render Directives
View source1. Install with the skills CLI
npx skills add vercel-labs/json-render/directives --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by vercel-labs@json-render/directives
Pre-built custom directives for @json-render/core. Drop them into your catalog and renderer to add formatting, math, string manipulation, and i18n.
Quick Start
import { standardDirectives } from '@json-render/directives';
// Wire into prompt generation
const prompt = catalog.prompt({ directives: standardDirectives });
// Wire into the renderer (React example)
import { JSONUIProvider, Renderer } from '@json-render/react';
<JSONUIProvider registry={registry} directives={standardDirectives}>
<Renderer spec={spec} registry={registry} />
</JSONUIProvider>
To add factory directives like createI18nDirective, spread the array:
import { standardDirectives, createI18nDirective } from '@json-render/directives';
const directives = [...standardDirectives, createI18nDirective(config)];
Defining Custom Directives
Use defineDirective from @json-render/core:
import { defineDirective, resolvePropValue } from '@json-render/core';
import { z } from 'zod';
const doubleDirective = defineDirective({
name: '$double',
description: 'Double a numeric value.',
schema: z.object({
$double: z.unknown(),
}),
resolve(value, ctx) {
const resolved = resolvePropValue(value.$double, ctx);
return (resolved as number) * 2;
},
});
Rules:
- Name must start with
$ - Name must not conflict with built-in keys (
$state,$cond,$computed,$template,$item,$index,$bindState,$bindItem) - Resolvers should call
resolvePropValueon sub-values to support composition
Built-in Directives
$format — Locale-aware value formatting
Formats values using Intl formatters. Supports date, currency, number, and percent.
{ "$format": "currency", "value": { "$state": "/cart/total" }, "currency": "USD" }
{ "$format": "date", "value": { "$state": "/user/createdAt" } }
{ "$format": "number", "value": 1234567, "notation": "compact" }
{ "$format": "percent", "value": 0.75 }
{ "$format": "date", "value": { "$state": "/post/createdAt" }, "style": "relative" }
Fields: $format (date | currency | number | percent), value (any expression), locale? (string), currency? (string, default "USD"), notation? (string), style? ("relative" for relative dates), options? (extra Intl options).
$math — Arithmetic operations
{ "$math": "add", "a": { "$state": "/subtotal" }, "b": { "$state": "/tax" } }
{ "$math": "round", "a": 3.7 }
Operations: add, subtract, multiply, divide, mod, min, max, round, floor, ceil, abs. Unary ops (round, floor, ceil, abs) only use a. Division by zero returns 0.
Fields: $math (operation enum), a? (first operand, default 0), b? (second operand, default 0).
$concat — String concatenation
{ "$concat": [{ "$state": "/user/firstName" }, " ", { "$state": "/user/lastName" }] }
Fields: $concat (array of values to resolve and join into a string).
$count — Array/string length
{ "$count": { "$state": "/cart/items" } }
Returns .length of arrays or strings, 0 for other types.
Fields: $count (value to count).
$truncate — Text truncation
{ "$truncate": { "$state": "/post/body" }, "length": 140, "suffix": "..." }
Fields: $truncate (value to truncate), length? (max chars, default 100), suffix? (string, default "...").
$pluralize — Singular/plural forms
{ "$pluralize": { "$state": "/cart/itemCount" }, "one": "item", "other": "items", "zero": "no items" }
Output: "3 items", "1 item", or "no items".
Fields: $pluralize (count value), one (singular label), other (plural label), zero? (zero label).
$join — Join array elements
{ "$join": { "$state": "/tags" }, "separator": ", " }
Fields: $join (array to join), separator? (string, default ", ").
createI18nDirective — Internationalization factory
import { createI18nDirective } from '@json-render/directives';
const tDirective = createI18nDirective({
locale: 'en',
messages: {
en: { "greeting": "Hello, {{name}}!", "checkout.submit": "Place Order" },
es: { "greeting": "Hola, {{name}}!", "checkout.submit": "Realizar Pedido" },
},
fallbackLocale: 'en',
});
Usage in specs:
{ "$t": "checkout.submit" }
{ "$t": "greeting", "params": { "name": { "$state": "/user/name" } } }
Fields: $t (translation key), params? (interpolation parameters, values accept expressions).
Config: locale (current locale), messages (Record<locale, Record<key, string>>), fallbackLocale? (fallback when key missing).
Composition
Directives compose naturally — each resolver calls resolvePropValue on its inputs, so directives can wrap other directives or built-in expressions:
{
"$format": "currency",
"value": { "$math": "multiply", "a": { "$state": "/price" }, "b": { "$state": "/qty" } },
"currency": "USD"
}
Resolves inside-out: $state reads from state, $math multiplies, $format formats as currency.
Wiring into Renderers
All four renderers (React, Vue, Svelte, Solid) accept directives on their provider and createRenderer output:
// Provider pattern
<JSONUIProvider registry={registry} directives={directives}>
<Renderer spec={spec} registry={registry} />
</JSONUIProvider>
// createRenderer pattern
const MyRenderer = createRenderer(catalog, components);
<MyRenderer spec={spec} directives={directives} />
For prompt generation, pass the same array:
const prompt = catalog.prompt({ directives });
Key Exports
| Export | Purpose |
|---|---|
formatDirective | $format directive definition |
mathDirective | $math directive definition |
concatDirective | $concat directive definition |
countDirective | $count directive definition |
truncateDirective | $truncate directive definition |
pluralizeDirective | $pluralize directive definition |
joinDirective | $join directive definition |
createI18nDirective | Factory for $t i18n directive |
standardDirectives | Array of all 7 non-factory directives |
I18nConfig | Type for i18n configuration |
Frequently asked questions about JSON Render Directives
Similar skills
Playwright Component Testing
Test React and Vue components in isolation with Playwright.
Fluent UI Blazor
Integrate Fluent UI components in Blazor applications effortlessly.
Build MCP App
Create interactive UI widgets for MCP servers.
Web Design Reviewer
Identify and fix design issues in websites efficiently.
Markstream Install
Seamlessly integrate Markstream for Markdown rendering.
GSAP & Framer Scroll Animation
Create advanced scroll animations effortlessly.
