Skip to content

leixingyu/jsonEditor

Repository files navigation

Json Editor

A python script for editing `.json` file based on Qt framework
Demo

About The Project


json-editor

.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.

Getting Started

Prerequisites

  • 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

Launch

  1. Unzip the json-editor package and rename is to something like jsonViewer

  2. You can either run main.py directly or:

    from jsonViewer import main
    main.show()

Features

Validation, sort and filtering

  • Data validation is a built-in feature that comes with the model/view architecture as type is preserved during setData() and data() methods. It then gets translated into qt element: str as QLineEdit; int as QSpinBox; float as QDoubleSpinBox

  • list and dict type data fully utilized the hierarchical support of QAbstractItemModel.

  • Sorting and Filtering are enabled with the help of QSortFilterProxyModel.

Serialization

Serialization and de-serialization in the QJsonModel enables functionalities like copy/paste (left) and drag/drop (right).

Copy and Paste Drag and Drop
copy/paste drag/drop

Raw View

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.

Roadmap

  • Json text view with syntax highlight
  • Json schema support
  • File drop
  • Custom stylesheet
  • Scripting interface for modular support
  • Web deployment (maybe?)

Reference

Model View Programming

QJsonModel