A JSON editor library that displays and manipulates JSON objects
npm install react-jsondata-editor
$ npm i react-jsondata-editor
`
Demo
- simple demo->
Demo
- Text area and JSON editor ->
Demo
Usage
`
import {JsonEditor} from "react-jsondata-editor"
{console.log(output)}} />
`
Props
| Prop | Type | Description |
| ---------------------- | ---------------- | -------------------------------------|
| jsonObject | JSON String | The initial value of a json String, it will be displayed on the view. The editor re-renders when the input of a Json string has been changed. It does not change the original input.
| onChange | callback function| It returns a stringify(JSON Object[output]) when the view of a Json object has been changed. It returns "undefined" when it has no data.
| theme | Object (optional)| Custom user theme(color and hoverColor). Example - themes: { color : '#9bb7d4', hoverColor : '#f4f7fa'}
| bannerStyle | Object (optional)| Custom user banner style(hoverColor, fontColor and font). Example - banner: { hoverColor: '#6690bd', fontColor : 'white', font: '20px/30px "Times New Roman", Times, serif'}
| keyStyle | Object (optional)| Custom user key style(color and font). Example - key : { color : 'black', font: '14px/20px "Times New Roman", Times, serif'}
| valueStyle | Object (optional)| Custom user value style(font, nullColor, booleanColor, numberColor and stringColor). Example - values : { font: '14px/20px Arial, Helvetica, sans-serif',, null : '#E9897E', boolean: '#8e4cad', number: '#25539a', string: '#797980' }
| buttonStyle | Object (optional)| Custom user button style(add/edit, delete, update and cancel). Example - buttons: { add: '#9bb7d4', delete: '#a0a2a4', update: '#9BB7D4', cancel: '#d49bb7'}
Simple
`javascript
import React from "react";
import {JsonEditor} from "react-jsondata-editor";
export default function Simple() {
let input =
'{"example":{"id":"json","age":99,"working":true,"problem":null,"more info":{"car":{"brand":"a-brand","year":2020,"owners":["father","brother"]}}}}'
return (
{console.log(output)}}/>
)
}
`
Text area and JSON editor
`javascript
import {useEffect, useState} from "react";
import {JsonEditor} from "../public/index";
import styles from '../styles/Index.module.css'
export default function Home() {
let currentEditObj ;
let input =
{
"example": {
"id": "json",
"age": 99,
"working": true,
"problem": null,
"more info": {
"car": {
"brand": "a-brand",
"year": 2020,
"owners": [
"father",
"brother"
]
}
}
}
}
const myStyle = {
theme: {
color : '#00A170',
hoverColor : '#f7f7f7'
},
bannerStyle: {
hoverColor: '#006e4d',
fontColor : 'white',
font: '20px/30px "Times New Roman", Times, serif'
},
keyStyle : {
color : 'black',
font: '14px/20px "Times New Roman", Times, serif'
},
valueStyle : {
font: '14px/20px Arial, Helvetica, sans-serif',
null : '#939597',
boolean: '#939597',
number: '#939597',
string: '#939597'
},
buttonStyle: {
add: '#006e4d',
delete: '#939597',
update: '#006e4d',
cancel: '#bb0039',
}
}
const [jsonInput, setJsonInput] = useState(JSON.stringify(input, null, ' '))
function textSave(e) {
setJsonInput(e.target.value)
}
function saveJsonString() {
if(currentEditObj === undefined){
setJsonInput('')
}else{
setJsonInput(currentEditObj)
}
}
return (
Json Editor (Demo)
{ currentEditObj = output }}
theme={myStyle.theme} bannerStyle={myStyle.bannerStyle} keyStyle={myStyle.keyStyle} valueStyle={myStyle.valueStyle} buttonStyle={myStyle.buttonStyle}
/>
)
}
``