Sections
File Viewer
- Overview
- Anatomy
- Header
- Navigation
- Renderers
JsonForm renders a whole JSON Schema as an editable form: nested objects
collapse into sections, arrays expand into repeatable rows, and each scalar is
typed (text, number, date, enum, checkbox). It's built entirely on shadcn's
FormField, so it inherits your theme, and form state is owned by a
react-hook-form instance you pass in.
JsonFormField is the unit of composition — render a single schema property by
its field path — and JsonForm is the thin convenience wrapper that renders a
whole schema and owns the <form>.
"use client";
import * as React from "react";
import type { JSONSchema7 } from "json-schema";
import { useForm } from "react-hook-form";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { JsonForm } from "@/components/json-form/json-form";
import sampleData from "@/components/json-form/sample/data.json";Usage
import { useForm } from "react-hook-form";
import { JsonForm } from "@/components/json-form/json-form";
export function Example() {
const form = useForm({
defaultValues: { invoice_number: "INV-1024", total: 1280.5 },
});
return (
<JsonForm
form={form}
schema={schema}
onSubmit={(data) => console.log(data)}
>
<button type="submit">Submit</button>
</JsonForm>
);
}Render a single field on its own:
import { JsonFormField } from "@/components/json-form/json-form";
export function VendorNameField() {
return (
<JsonFormField name="vendor.name" schema={{ type: "string" }} required />
);
}API Reference
JsonForm
| Prop | Type | Description |
|---|---|---|
form | UseFormReturn | A react-hook-form instance holding the data values. |
schema | JSONSchema7 | The schema describing the form's structure. |
onSubmit | SubmitHandler | Optional submit handler for the underlying <form>. |
textInput | "input" | "textarea" | Optional override for plain string fields. Omit it to keep the default auto behavior (format: "textarea" or long strings render as textareas). |
sourceLink | SourceFieldLink from source-field-link | Opt into field-level source linking — every scalar becomes a hoverable card that reports its path and highlights when active (wire it from useSegmentedSourceFieldLink). |
children | ReactNode | Rendered after the fields, e.g. a submit button. |
className | string | Class names for the form container. |
JsonFormField
| Prop | Type | Description |
|---|---|---|
name | string | The react-hook-form field path, e.g. vendor.name or items.0. |
schema | JSONSchema7 | The schema for this property. |
required | boolean | Marks the field required. |
label | string | Override the derived label. |
textInput | "input" | "textarea" | Optional override for plain string fields. |