Top Related Projects
JSON Schema Based Editor
A browser based code editor
Ace (Ajax.org Cloud9 Editor)
In-browser code editor (version 5, legacy)
Quill is a modern WYSIWYG editor built for compatibility and extensibility
Quick Overview
JSONEditor is a web-based tool for viewing, editing, formatting, and validating JSON. It provides a tree editor for structured editing, a code editor for raw text editing, and a preview mode for a read-only representation. The library can be used to create JSON editors in web applications, offering a user-friendly interface for working with JSON data.
Pros
- Versatile editing modes (tree, code, and preview)
- Customizable appearance and functionality
- Supports large JSON documents with good performance
- Actively maintained with regular updates
Cons
- Learning curve for advanced features and customization
- Limited built-in validation options (though extensible)
- May be overkill for simple JSON editing tasks
- Requires additional setup for server-side integration
Code Examples
Creating a basic JSON editor:
const container = document.getElementById('jsoneditor');
const options = {};
const editor = new JSONEditor(container, options);
// Set JSON data
const initialJson = { "name": "John", "age": 30 };
editor.set(initialJson);
Retrieving edited JSON data:
const updatedJson = editor.get();
console.log(updatedJson);
Using a custom schema for validation:
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number", minimum: 0 }
},
required: ["name", "age"]
};
const options = {
schema: schema,
schemaRefs: undefined
};
const editor = new JSONEditor(container, options);
Getting Started
-
Install JSONEditor via npm:
npm install jsoneditor
-
Include the necessary files in your HTML:
<link href="path/to/jsoneditor.min.css" rel="stylesheet" type="text/css"> <script src="path/to/jsoneditor.min.js"></script>
-
Create a container element in your HTML:
<div id="jsoneditor" style="width: 400px; height: 400px;"></div>
-
Initialize the editor in your JavaScript:
const container = document.getElementById('jsoneditor'); const options = {}; const editor = new JSONEditor(container, options);
-
Set initial JSON data:
const initialJson = { "example": "data" }; editor.set(initialJson);
Competitor Comparisons
JSON Schema Based Editor
Pros of json-editor
- More customizable with a wider range of form controls and input types
- Better support for complex JSON schemas with nested objects and arrays
- Offers a more comprehensive set of validation options
Cons of json-editor
- Less visually appealing out-of-the-box interface
- Steeper learning curve for implementation and customization
- Limited built-in support for viewing and editing raw JSON
Code Comparison
jsoneditor:
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);
editor.set(json);
json-editor:
var element = document.getElementById('editor_holder');
var editor = new JSONEditor(element, {
schema: schema,
theme: 'bootstrap4'
});
editor.setValue(startval);
Both libraries provide JSON editing capabilities, but they have different focuses. jsoneditor is more oriented towards direct JSON manipulation with a clean interface, while json-editor is geared towards generating form-based editors from JSON schemas. The choice between them depends on the specific requirements of your project, such as the complexity of your JSON structure, the need for schema validation, and the desired user interface.
A browser based code editor
Pros of monaco-editor
- More versatile, supporting multiple programming languages beyond JSON
- Offers advanced features like IntelliSense, code folding, and multi-cursor editing
- Highly customizable with a rich API for extending functionality
Cons of monaco-editor
- Larger file size and potentially higher resource usage
- Steeper learning curve for implementation and customization
- May be overkill for simple JSON editing tasks
Code Comparison
monaco-editor:
require.config({ paths: { 'vs': 'https://unpkg.com/monaco-editor/min/vs' }});
require(['vs/editor/editor.main'], function() {
var editor = monaco.editor.create(document.getElementById('container'), {
value: '{\n\t"key": "value"\n}',
language: 'json'
});
});
jsoneditor:
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);
var json = { "key": "value" };
editor.set(json);
Summary
Monaco Editor is a powerful, full-featured code editor that supports multiple languages, while JSON Editor is specifically designed for JSON editing. Monaco Editor offers more advanced features and customization options but comes with a larger footprint and complexity. JSON Editor is simpler to implement and use for JSON-specific tasks but lacks the versatility of Monaco Editor.
Ace (Ajax.org Cloud9 Editor)
Pros of Ace
- More versatile, supporting multiple programming languages and file types
- Highly customizable with a wide range of features and plugins
- Better performance for large files due to its optimized rendering engine
Cons of Ace
- Steeper learning curve for implementation and customization
- Larger file size and potentially higher resource usage
- Less specialized for JSON editing compared to JSONEditor
Code Comparison
JSONEditor:
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);
Ace:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
Summary
While Ace offers a more comprehensive editing experience for various languages, JSONEditor provides a specialized solution for JSON data. Ace excels in flexibility and performance for large files, but requires more setup and customization. JSONEditor, on the other hand, offers a simpler implementation specifically tailored for JSON editing tasks.
In-browser code editor (version 5, legacy)
Pros of CodeMirror 5
- More versatile, supporting multiple programming languages and formats
- Highly customizable with a rich set of extensions and themes
- Better performance for large documents
Cons of CodeMirror 5
- Steeper learning curve for implementation and customization
- Less specialized for JSON editing compared to JSONEditor
- Requires more setup for specific JSON-related features
Code Comparison
JSONEditor:
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);
CodeMirror 5:
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
mode: 'application/json',
lineNumbers: true
});
Summary
JSONEditor is specifically designed for JSON editing, offering a user-friendly interface with built-in validation and formatting. It's easier to set up for JSON-specific tasks but less flexible for other languages.
CodeMirror 5 is a more general-purpose code editor that can handle various languages, including JSON. It provides greater customization options and better performance for large documents but requires more configuration for JSON-specific features.
The choice between the two depends on the specific needs of the project. If the focus is solely on JSON editing, JSONEditor might be more suitable. For projects requiring a versatile code editor with JSON support, CodeMirror 5 could be the better option.
Quill is a modern WYSIWYG editor built for compatibility and extensibility
Pros of Quill
- Rich text editing capabilities with a wide range of formatting options
- Customizable and extensible through modules and themes
- Better suited for content creation and document editing
Cons of Quill
- Not specifically designed for JSON editing or visualization
- May require additional setup for handling structured data like JSON
- Less focused on data validation and schema enforcement
Code Comparison
Quill:
var quill = new Quill('#editor', {
theme: 'snow'
});
quill.setText('Hello World!');
JSONEditor:
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);
editor.set({key: 'value'});
Key Differences
- JSONEditor is specialized for JSON data editing and visualization
- Quill focuses on rich text editing and content creation
- JSONEditor provides built-in JSON validation and formatting
- Quill offers more text styling and formatting options
- JSONEditor is better suited for working with structured data
- Quill excels in creating formatted documents and articles
Both libraries serve different purposes, with JSONEditor being more appropriate for JSON-specific tasks and data manipulation, while Quill is better for general content creation and rich text editing.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
JSON Editor
JSON Editor is a web-based tool to view, edit, format, and validate JSON. It has various modes such as a tree editor, a code editor, and a plain text editor. The editor can be used as a component in your own web application. It can be loaded as CommonJS module, AMD module, or as a regular javascript file.
The library was originally developed as core component of the popular web application https://jsoneditoronline.org and has been open sourced since then.
Supported browsers: Chrome, Firefox, Safari, Edge.
Cross browser testing for JSONEditor is generously provided by BrowserStack
Successor: svelte-jsoneditor
This library jsoneditor
has a successor: svelte-jsoneditor
. The new editor is not a one-to-one replacement, so there may be reasons to stick with jsoneditor
.
The main differences between the two are described here.
Features
JSONEditor has various modes, with the following features.
Tree mode
- Change, add, move, remove, and duplicate fields and values.
- Sort arrays and objects.
- Transform JSON using JMESPath queries.
- Colorized code.
- Color picker.
- Search & highlight text in the tree view.
- Undo and redo all actions.
- JSON schema validation (powered by ajv).
Code mode
- Colorized code (powered by Ace).
- Inspect JSON (powered by Ace).
- Format and compact JSON.
- Repair JSON.
- JSON schema validation (powered by ajv).
Text mode
- Format and compact JSON.
- Repair JSON.
- JSON schema validation (powered by ajv).
Preview mode
- Handle large JSON documents up to 500 MiB.
- Transform JSON using JMESPath queries.
- Format and compact JSON.
- Repair JSON.
- JSON schema validation (powered by ajv).
Documentation
Install
with npm (recommended):
npm install jsoneditor
Alternatively, you can use another JavaScript package manager like https://yarnpkg.com/, or a CDN such as https://cdnjs.com/ or https://www.jsdelivr.com/.
Use
Note that in the following example, you'll have to change the urls
jsoneditor/dist/jsoneditor.min.js
andjsoneditor/dist/jsoneditor.min.css
to match the place where you've downloaded the library, or fill in the URL of the CDN you're using.
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- when using the mode "code", it's important to specify charset utf-8 -->
<meta charset="utf-8">
<link href="jsoneditor/dist/jsoneditor.min.css" rel="stylesheet" type="text/css">
<script src="jsoneditor/dist/jsoneditor.min.js"></script>
</head>
<body>
<div id="jsoneditor" style="width: 400px; height: 400px;"></div>
<script>
// create the editor
const container = document.getElementById("jsoneditor")
const options = {}
const editor = new JSONEditor(container, options)
// set json
const initialJson = {
"Array": [1, 2, 3],
"Boolean": true,
"Null": null,
"Number": 123,
"Object": {"a": "b", "c": "d"},
"String": "Hello World"
}
editor.set(initialJson)
// get json
const updatedJson = editor.get()
</script>
</body>
</html>
Build
The code of the JSON Editor is located in the folder ./src
. To build
jsoneditor:
-
Install dependencies:
npm install
-
Build JSON Editor:
npm run build
This will generate the files
./jsoneditor.js
,./jsoneditor.css
, and
minified versions in the dist of the project. -
To automatically build when a source file has changed:
npm start
This will update
./jsoneditor.js
and./jsoneditor.css
in the dist folder on every change, but it will NOT update the minified versions as that's an expensive operation.
Test
Run unit tests:
npm test
Run code linting (JavaScript Standard Style):
npm run lint
Custom builds
The source code of JSONEditor consists of CommonJS modules. JSONEditor can be bundled in a customized way using a module bundler like browserify or webpack. First, install all dependencies of jsoneditor:
npm install
To create a custom bundle of the source code using browserify:
browserify ./index.js -o ./jsoneditor.custom.js -s JSONEditor
The Ace editor, used in mode code
, accounts for about one third of the total
size of the library. To exclude the Ace editor from the bundle:
browserify ./index.js -o ./jsoneditor.custom.js -s JSONEditor -x brace -x brace/mode/json -x brace/ext/searchbox
To minify the generated bundle, use uglifyjs:
uglifyjs ./jsoneditor.custom.js -o ./jsoneditor.custom.min.js -m -c
License
jsoneditor
is released as open source under the permissive the Apache 2.0 license.
If you are using jsoneditor commercially, there is a social (but no legal) expectation that you help fund its maintenance. Start here.
Top Related Projects
JSON Schema Based Editor
A browser based code editor
Ace (Ajax.org Cloud9 Editor)
In-browser code editor (version 5, legacy)
Quill is a modern WYSIWYG editor built for compatibility and extensibility
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot