A python script for editing `.json` file based on Qt framework
Demo
.json
files are heavily dependent in production environment and there are
many benefits of creating a standalone editor instead of editing the text file directly.
Not everyone is fan of working with a text editor (like artists) and no one
can be confident to avoid syntax error in their edits.
Moreover, a standalone tool supports features like version control,
validation, schema and more.
The goal of this tool initially serves as my model view programming practice in PyQt,
but then I thought, why not iterate on it and make it user-friendly, portable and minimal? My goal now is to make this
modular and easily embeddable, so to create a standardized way for displaying and editing .json
file across applications.
-
Qt: a module that supports different python qt bindings
or alternatively, change the code below to whatever qt binding you have on your machine.
from Qt import QtWidgets, QtCore, QtGui from Qt import _loadUi
-
Unzip the json-editor package and rename is to something like
jsonViewer
-
You can either run
main.py
directly or:from jsonViewer import main main.show()
-
Data validation is a built-in feature that comes with the model/view architecture as type is preserved during
setData()
anddata()
methods. It then gets translated into qt element:str
asQLineEdit
;int
asQSpinBox
;float
asQDoubleSpinBox
-
list
anddict
type data fully utilized the hierarchical support ofQAbstractItemModel
. -
Sorting and Filtering are enabled with the help of
QSortFilterProxyModel
.
Serialization and de-serialization in the QJsonModel
enables functionalities like copy/paste (left)
and drag/drop (right).
Copy and Paste | Drag and Drop |
---|---|
The tool also has a built-in text editor with syntax highlighting known as the raw view.
As shown, the data between the tree view and the raw view are interchangeable.
- Json text view with syntax highlight
- Json schema support
- File drop
- Custom stylesheet
- Scripting interface for modular support
- Web deployment (maybe?)