JSON Viewer with Editor
How to edit a json file in react
Finding a JSON editor tool
Any react JSONeditor that can highlight difference between two objects?
Videos
» npm install json-edit-react
I'm looking for feedback on react-json-view
it's a production-ready component for displaying and interacting with JSON objects.
Here's the Component Demo
features include:
base-16 themes
add/edit/delete nodes
clipboard enabled
clickable collapse/expand
I see this component being useful for any technical docs that allude to JSON data structures.
what would you use it for?
what features would you like to see added?
is there any reason this wouldn't be your go-to JSON and array viewer?
thank you for feedback!
» npm install react-json-editor-ajrm
» npm install @charanjeet123/react-json-editor-ui
» npm install jsoneditor-react
You can use some JSON editor like react-ace
Put your json file in assets, then import it to your component and follow the guide on the README! Your component would look like:
Copyconst [text, setText] = useState(JSON.stringify(yourJsonFile, null, 2));
function handleChange(text, event) {
try {
setText(text && JSON.parse(text));
} catch (error) {
// pass, user is editing
}
}
return (
<AceEditor
mode="java"
theme="github"
onChange={handleChange}
name="UNIQUE_ID_OF_DIV"
editorProps={{ $blockScrolling: true }}
value={text}
/>
);
In a React project, all your source code and assets are in the src folder. The compiler will put everything you need in the public folder. If the JSON file is not copied, you might need a plugin that copies static files to the public folder.
About your other question: do you want the user to be able to edit the JSON as a text string? Then you can just load the JSON and keep it as a string. That string you could put into some text input field. It could look something like this:
Copyfetch('assets/myfile.json')
.then(responseString => {
myEditableTextField.value = responseString
})
To store the results after the user edited it, you will still need some kind of server page (NodeJS or PHP) that can save the file back to a JSON file after editing.
But note this is still bad practice. There is an extremely high chance that the JSON will not be correct after the user has edited it.
It would be better to build some kind of CMS that edits all the JSON properties separately.
Copyfetch('assets/myfile.json')
.then(responseString => responseString.json())
.then(data => {
myEditablenameField.value = data.name
// etc. for all values in the json file
})