import Link from "next/link"; import { Code } from "@/components/code"; export const metadata = { title: "Data Binding | json-render", }; export default function DataBindingPage() { return (

Data Binding

Connect UI components to your application data using JSON Pointer paths.

JSON Pointer Paths

json-render uses JSON Pointer (RFC 6901) for data paths:

{`// Given this data: { "user": { "name": "Alice", "email": "alice@example.com" }, "metrics": { "revenue": 125000, "growth": 0.15 } } // These paths access: "/user/name" -> "Alice" "/metrics/revenue" -> 125000 "/metrics/growth" -> 0.15`}

DataProvider

Wrap your app with DataProvider to enable data binding:

{`import { DataProvider } from '@json-render/react'; function App() { const initialData = { user: { name: 'Alice' }, form: { email: '', message: '' }, }; return ( {/* Your UI */} ); }`}

Reading Data

Use useDataValue for read-only access:

{`import { useDataValue } from '@json-render/react'; function UserGreeting() { const name = useDataValue('/user/name'); return

Hello, {name}!

; }`}

Two-Way Binding

Use useDataBinding for read-write access:

{`import { useDataBinding } from '@json-render/react'; function EmailInput() { const [email, setEmail] = useDataBinding('/form/email'); return ( setEmail(e.target.value)} /> ); }`}

Using the Data Context

Access the full data context for advanced use cases:

{`import { useData } from '@json-render/react'; function DataDebugger() { const { data, setData, getValue, setValue } = useData(); // Read any path const revenue = getValue('/metrics/revenue'); // Write any path const updateRevenue = () => setValue('/metrics/revenue', 150000); // Replace all data const resetData = () => setData({ user: {}, form: {} }); return
{JSON.stringify(data, null, 2)}
; }`}

In JSON UI Trees

AI can reference data paths in component props:

{`{ "type": "Metric", "props": { "label": "Total Revenue", "valuePath": "/metrics/revenue", "format": "currency" } }`}

Next

Learn about actions for user interactions.

); }