Skip to content
Protocore Design Systemv1.6.9

/// Inputs

JsonInput

A mono Textarea that validates JSON on blur, surfaces the parse error in danger tone, and can pretty-print the value.

import { JsonInput } from "@protocore/pds";
View as Markdown

Basics

Type JSON and blur the field: valid input clears, invalid input shows the parser's message and marks the field invalid. Controllable via value / onValueChange.

Format button

Set withFormatButton to add a Format action that pretty-prints valid JSON on demand; formatOnBlur does the same automatically when the field loses focus.

When to use it

Use JsonInput where a user authors raw JSON — a webhook payload, a config blob, a metadata field — and needs immediate feedback that it parses. To only display JSON, use JsonViewer or a CodeBlock. This control validates syntax, not shape: pair it with a schema check on submit for structural validation.

Usage

Do

  • Give it an `aria-label` (or wrap it in a `Field`).
  • Use `onValidationChange` to disable submit while the JSON is invalid.
  • Offer `withFormatButton` for anything a human hand-edits.

Don't

  • Don't treat a valid parse as a valid document — check the shape separately.
  • Don't reformat on every keystroke; format on blur or on demand.
  • Don't hide the error — it names exactly where parsing failed.

Accessibility

  • The parse error renders in a `role="alert"` region and is referenced by the field's `aria-describedby`.
  • The field carries `aria-invalid` while the value fails to parse.
  • Spellcheck and autocomplete are disabled — this is code, not prose.

JsonInput props

PropTypeDefaultDescription
autoResizebooleanGrow to fit content instead of scrolling.
classNamestring
defaultValuestringInitial text when uncontrolled.
formatOnBlurbooleanfalsePretty-print the value on blur when it parses. Default `false`.
indentnumber2Indentation width for formatting. Default `2`.
onValidationChange((error: string | null) => void)Called when validity changes: the parse-error message, or `null` when valid/empty.
onValueChange((value: string) => void)Fires with the raw text on every keystroke.
sizeenummdControl padding scale. Default `md`.
styleCSSProperties
valuestringControlled text value. Pair with `onValueChange`.
withFormatButtonbooleanfalseRender a "Format" button that pretty-prints on demand. Default `false`.

Related

  • TextareaSunken multi-line text control, with an opt-in auto-resize that grows the field to fit its content.
  • InputThe base single-line text control — a sunken field with optional leading and trailing adornment slots.
  • CodeBlockMonospace code panel — sunken surface, hairline border, and an optional title bar.
  • JsonViewerA collapsible JSON tree that auto-masks sensitive keys, with copy and expand/collapse-all.