Docyrus

JsonSchemaForm

Render a JSON Schema as a native form — create, edit and read-only view modes, nested objects, arrays and a root array, with the web schema-to-field mapping.

iOSAndroid
Preview JsonSchemaForm on your device

Scan with Expo Go

Download Expo Go, then scan the QR code to preview native components.

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-json-schema-form
Required Packages(1 package)
pnpm add tailwind-variants

Usage

import { JsonSchemaForm } from '@/components/docyrus-native/json-schema-form';
import { type JsonSchema } from '@/hooks/docyrus-native/use-docyrus-data-source-json-schema';

const schema: JsonSchema = {
  type: 'object',
  title: 'Customer',
  required: ['name', 'email'],
  properties: {
    name: { type: 'string', title: 'Name' },
    email: { type: 'string', format: 'email' },
    tier: { type: 'string', enum: ['free', 'pro', 'enterprise'] },
    address: {
      type: 'object',
      properties: { city: { type: 'string' }, zip: { type: 'string' } }
    },
    tags: { type: 'array', items: { type: 'string' } }
  }
};

export function CustomerForm() {
  return (
    <JsonSchemaForm
      schema={schema}
      mode="create"
      onChange={value => console.log(value)}
      onSubmit={async value => save(value)} />
  );
}

Pair it with useDocyrusDataSourceJsonSchema to build the schema from a data source's fields.

Schema → field mapping

SchemaField
enum with ≤ 4 valuesfield-radioGroup (labels from x-enumNames / enumNames / x-enum-labels / x-enumLabels, else humanized)
enum with > 4 valuesfield-select
booleanfield-switch
number / integerfield-number
string + contentMediaType: application/jsonMonospace code input with JSON parse validation (value stays a string)
format: email / uri / urlfield-email / field-url
format: date / date-time / datetime / timefield-date / field-dateTime / field-time
format: password / color / hex-colorfield-password / field-color
format: textarea / multiline, or maxLength > 160field-textarea
other stringfield-text
objectOutlined Card group (root object renders flat)
arraySchemaRepeater (minItems / maxItems honoured); tuple items supported

Inputs render through DocyFieldDynamic; mode="view" renders values through DocyValueDynamic. Enum values keep their original JSON type (strings, numbers, booleans, null). Empty strings / nulls are dropped from the emitted value, and empty nested objects / arrays are omitted (the root is always emitted).

API Reference

PropTypeDefaultDescription
schemaJsonSchema—Required. Root object or root array schema
dataRecord<string, unknown> | unknown[] | null—Initial / external value. External changes re-seed the form unless they echo the last emitted value
mode'create' | 'edit' | 'view''create'view renders read-only values
disabledboolean—Disable every input and the submit button
submitLabelstring'Save'Full-width submit button label (rendered only with onSubmit)
onChange(value: JsonSchemaFormData) => void—Called with the denormalized value on every change
onSubmit(value: JsonSchemaFormData) => void | Promise<void>—Called on submit after required + JSON validation pass; the button shows a spinner while it resolves
emptyStateReactNode—Rendered for an object without properties or an empty array (view mode)
classNamestring—Container className

Components

ComponentDescription
JsonSchemaFormSchema-driven form (create / edit / view)

Type Exports

TypeDescription
JsonSchemaFormPropsProps for JsonSchemaForm
JsonSchemaFormMode'create' | 'edit' | 'view'
JsonSchemaFormDataRecord<string, unknown> | Array<unknown>

JsonSchema itself is exported by use-docyrus-data-source-json-schema.

Differences from web

  • No @tanstack/react-form — state is a plain immutable value tree inside the component.
  • Always a single column; ref and HTML div attributes are dropped (className is kept).
  • On submit, required properties and JSON inputs are validated and errors are shown inline (web submits without schema validation).

Translation keys

ui.jsonSchemaForm.submit, ui.jsonSchemaForm.form, ui.jsonSchemaForm.group, ui.jsonSchemaForm.item, ui.jsonSchemaForm.add, ui.jsonSchemaForm.noFields, ui.jsonSchemaForm.noItems, ui.jsonSchemaForm.required, ui.jsonSchemaForm.invalidJson (English fallbacks; the web component hardcodes this copy).

On this page