JsonField

Lightweight read-only JSON formatter rendered as a <pre>. No Monaco dependency — safe to use in List cells or anywhere a heavy editor would be overkill.

Usage

import { List, DataTable } from "@/components/admin";
import { JsonField } from "@/components/monaco";
 
const ProductList = () => (
  <List>
    <DataTable>
      <DataTable.Col source="id" />
      <DataTable.Col>
        <JsonField source="metadata" />
      </DataTable.Col>
    </DataTable>
  </List>
);

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
indentOptionalnumber2Indent passed to JSON.stringify
emptyOptionalReactNode-Rendered when the value is null or undefined
classNameOptionalstring-Classes appended to the <pre>
recordOptionalobjectContextRecord to read from (defaults to RecordContext)
defaultValueOptionalunknown-Fallback when the field is missing from the record

Behavior

  • Objects, arrays, numbers, booleans: rendered via JSON.stringify(value, null, indent).
  • Strings: parsed with JSON.parse and re-stringified. If the string is not valid JSON, it's rendered verbatim.
  • null or undefined: renders the empty prop (or nothing if empty is not provided).

No syntax highlighting in v1. If you need highlighting, use <MonacoJsonField>.