Skip to content

JsonEditor

JSON checked as it is typed: where the mistake is, in words, and a button that tidies it up.

import { JsonEditor } from '@sypnia/ui/react'

On this page
  1. A test event
  2. When to use it
  3. For everyone
  4. Props

A test event

The JSON has a mistake on line 3. Check the commas, quotes and brackets there.

Code
import { useState } from 'react';
import { Field, JsonEditor } from '@sypnia/ui/react';

// The comma after «true» is a mistake: it says on which line. Remove it and press «Tidy up».
export default function Body() {
  const [json, setJson] = useState('{"event": "order.paid",\n  "notify": true,\n}');
  return <Field label="Test event"><JsonEditor value={json} onChange={setJson} rows={6} /></Field>;
}

When to use it

Use it when

  • Test events, settings written as JSON.

Do not use it when

  • Settings with a known shape: give them their own fields.

For everyone

  • A mistake marks the field invalid and is said with the line number.

Props

JsonEditorTypeDefault
onChangerequired (v: string) => void
valuerequired string
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks the value as wrong. Inside a `<Field error>` it is set for you.

boolean
onRun

Runs with Ctrl/⌘ + Enter.

(() => void)
placeholder string
readOnly boolean
rows

Visible lines before it scrolls.

number
  1. A test event
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms