JSON Field

Validates JSON as you type, points at the exact line and column, and repairs the usual hand-editing mistakes in one tap.

StopsBroken JSON saved to config

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/json-field.json

The files land in your project. They're yours to edit.

Usage

json-field-usage.tsx
import { JsonField } from "@/components/ui/json-field"

return <JsonField label="Service config" defaultValue={pasted} rows={7} className="max-w-sm" />

What it catches

  • Trailing commas
  • Single or smart quotes, and unquoted keys
  • Comments and Python literals such as True and None
  • Missing commas and unclosed braces or brackets
  • Exact line and column, the same in every browser

Props

JsonField props
PropTypeDefault
label

Visible label.

string"JSON"
hint

Helper text shown while the field is empty.

string—
value

Controlled value.

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the text on every change, including fixes and formatting.

(value: string) => void—
delay

Pause in ms before a problem is shown while typing. Leaving the field shows it at once.

number600
indent

Indent used by the Format button.

number2
formatLabel

Format button text.

string"Format"
validMessage

Shown under valid JSON.

string"Valid JSON"
fixLabels

Labels of the one-tap fixes, per mistake.

Partial<Record<JsonMistake, string>>—
showLabel

Text of the button that selects the problem in the textarea.

string"Show me"
formatPosition

Formats the position shown before each problem.

(line: number, column: number) => string(line, column) => `Line ${line}, column ${column}:`

* required. Also accepts the native props of <textarea> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible label; textarea has aria-invalid and is described by the status
  • Status is a polite live region and problems wait for a pause while typing
  • Position button moves the caret to the problem
  • Caret overlay is aria-hidden

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Checks syntax only; no JSON Schema validation
  • Fixes are heuristic; review the result before saving

What it stops

Broken JSON saved to config

Also known as

json · json editor · json validator · config · payload · metadata · settings · api body

Field type

Dependencies

Pairs well with