JSONEdit lets you edit a JSON Document using an intuitive GUI.
The GUI adds features that simple text editors will not have by default. The structure of the JSON document is both editable and clearly visible for you the user. JSONEdit also understands the types of elements in a document which allows simple forms of validation to be applied to these types to ensure the JSON that is written remains valid and follows semantics without the need for a schema document.
When saving JSON it is useful for the document to follow a set format so you can easily compare one revision of the document with another. JSONEdit will pretty print JSON when it writes documents to disk. The elements of the document are sorted alphabetically so they remain in the same order between revisions. The JSON is indented to make the structure clearer when viewing the document outside of JSONEdit - for example with vi or notepad.
The process of editing is made efficient with a context menu providing commands to alter the structure of the document tree and a simple text editor that allows multi-line editing. This is useful as JSON does not natively allow a string to span more than a single line in a file. JSONEdit takes care of escaping newline characters for you in the file but on screen the editor will display newlines as you would expect to see them.
As a stand alone program, JSONEdit is entirely local to your device. You can be sure your data is not shared with an online website and you do not require an internet connection to edit JSON. This is useful if data you are editing must be kept secure, or you are working in a disconnected environment.
JSONEdit is free to download and run sunder python on Windows, MacOS or Linux. It is part of the toolchest on GitHub. You may clone the git repository using:
JSONEdit is cross platform and is known to work in the following environments where Python 2 or 3 is installed:
Once installed it can be run over an ssh connection if you have a local X Windows server available such as XQuartz. This is useful in embedded applications such as routers and IOT devices.
To start JSONEdit ensure the installation directory is in your path and run:
Once started the main editor window will appear. There are three components to the editor window: the menubar, the document tree, and the editor pane.
The menubar has a simple file menu with the following commands:
The title of the application window includes the name of the current file and an asterisk '*' indicating the current file is dirty and should be saved to persist edits to your filesystem.
The document tree presents you with a hierarchical view of the entire JSON document. You may expand and collapse nodes of the tree to focus on the elements you are most interested in.
If you click on items in the tree they will appear in full in the editor pane to the right if they are leaves of the document tree or the keys of leaves in the tree. Any edits made to the editor pane update the JSON tree in real time. If for example you are editing a numeric key but enter a string that can not represent a number value you will immediately see in the tree that the value has become 0 rather than the value you have typed.
Right clicking in the document tree view will call up a context sensitive command menu. It has the following options:
To edit the values held in your document select the value in the document tree view. The Editor pane to the right will then hold the value of the selected document node. You may then edit the value in this pane. As the value is typed the document tree will be updated. if the type of the node requires the format of the value to be a certain way you can see if the result is as expected by looking at the live preview in the document tree.
A key feature of the editor pane is support for multi-line editing. Any unescaped \n sequence in the source JSON will become a newline in the editor pane which provides a more natural editing experience rather than having to work with a very long wrapped string. This was the original motivation for creating the editor.
JSONEdit has a compact design. The initial goal was to produce an editor allowing editing of embedded strings in a more natural manner than using a vanilla text editors. The issue being that JSON format does not allow values to span more than one line in the JSON source. This results in multi-line strings being stored in string literals with \n character sequences that obscure the structure of text held in the string value.
A secondary concern was to build an editor quickly with as small a footprint as possible. For this reason Python was chosen for its compact source code form. An additional benefit provided by the use of Python along with the Ttk GUI toolkit was that the editor became cross platform with no extra work.
Having chosen Python it was simple to make the project Open Source allowing users to extend the editor themselves or re-purpose it for editing other types of hierarchical data. Bugs could be fixed easily and users are very welcome to contribute new features back to the original git repository
The overall design of the Editor follows the MVVM design pattern. The main file contains three clearly distinct classes to provide the Model, View, and Viewmodel of the MVVM pattern. Consult the source for further information.