
A highly-configurable React component for editing or viewing JSON/object data
undefined, BigInt, Symbol)💡 Try the Live Demo to see these features in action!

📣️ ANNOUNCEMENT
V2 of json-edit-react is now available in beta, with significant refactors and performance improvements.
npm install json-edit-react@beta yarn add json-edit-react@beta pnpm add json-edit-react@beta❗️ If you're upgrading from V1, be sure to read the migration guide.📖️ FULL DOCS
If you've got any suggestions, please join the discussion here.
# Depending on your package manager:
npm i json-edit-react
# OR
yarn add json-edit-react
import { JsonEditor } from 'json-edit-react'
// In your React component:
return (
<JsonEditor
data={ jsonData }
setData={ setJsonData } // optional
{ ...otherProps } />
);
(for end user)
It's pretty self explanatory (click the "edit" icon to edit, etc.), but there are a few not-so-obvious ways of interacting with the editor:
Cmd/Ctrl/Shift-Enter to add a new line (Enter submits the value)Enter for new line, and Cmd/Ctrl/Shift-Enter for submitEscape to cancel editingCmd/Ctrl will copy the path to the selected node rather than its valueTab/Shift-Tab keys.jsonParse prop.Have a play with the Demo app to get a feel for it!
The only required property is data (although you will need to provide a setData method to update your data).
This is a reference list of all possible props, divided into related sections. Most of them provide a link to a section below in which the concepts are explored in more detail.
| Prop | Type | Default | Description |
|---|---|---|---|
data |
object\|array |
none | The data to be displayed / edited |
setData |
object\|array => void |
none | Method to update your data object. See Managing state below for additional notes. |
onUpdate |
UpdateFunction |
none | A function to run whenever a value is updated (edit, delete or add) in the editor. See Update functions. |
onEdit |
UpdateFunction |
none | A function to run whenever a value is edited. |
onDelete |
UpdateFunction |
none | A function to run whenever a value is deleted. |
onAdd |
UpdateFunction |
none | A function to run whenever a new property is added. |
onChange |
OnChangeFunction |
none | A function to modify/constrain user input as they type — see OnChange functions. |
onError |
OnErrorFunction |
none | A function to run whenever the component reports an error — see OnErrorFunction. |
enableClipboard |
boolean\|CopyFunction |
true |
Enable or disable the "Copy to clipboard" button in the UI. — see Copy Function |
| Prop | Type | Default | Description |
|---|---|---|---|
restrictEdit |
boolean\|FilterFunction |
false |
If true, no editing at all is permitted. A callback function can be provided — see Advanced Editing Control |
restrictDelete |
boolean\|FilterFunction |
false |
As with restrictEdit but for deletion |
restrictAdd |
boolean\|FilterFunction |
false |
As with restrictEdit but for adding new properties |
restrictTypeSelection |
boolean\|DataType[]\|TypeFilterFunction |
false |
For restricting the data types the user can select, including Custom Node types, and Enums — see Data Type Restrictions |
newKeyOptions |
string[] \| NewKeyOptionsFunction |
none | New keys can be restricted to certain values — see New Key Restrictions & Default Values |
defaultValue |
any\|DefaultValueFilterFunction |
null |
Value that new properties are initialised with — see New Key Restrictions & Default Values |
restrictDrag |
boolean\|FilterFunction |
true |
Set to false to enable drag and drop functionality — see Drag-n-drop |
viewOnly |
boolean |
A shorthand if you just want the component to be a viewer, with no editing at all. Overrides any of the above edit restrictions. |
| Prop | Type | Default | Description |
|---|---|---|---|
theme |
ThemeInput |
defaultTheme |
Either one of the built-in themes (imported separately), or an object specifying some or all theme properties — see Themes. |
icons |
{[iconName]: JSX.Element, ... } |
{ } |
Replace the built-in icons by specifying them here — see Themes. |
showIconTooltips |
boolean |
false | Display icon tooltips when hovering. |
indent |
number |
3 |
Specify the amount of indentation for each level of nesting in the displayed data. |
collapse |
boolean\|number\|FilterFunction |
false |
Defines which nodes of the JSON tree will be displayed "opened" in the UI on load — see Collapse. |
$ claude mcp add json-edit-react \
-- python -m otcore.mcp_server <graph>