Skip to main content

A set of tools to manipulate JSON: diff, patch, pretty-printing

Project description

Manipulate JSON documents using “JSON patch” format.

Installation

$ pip install json_tools

Release notes

Check the project’s Wiki

Usage

There are two ways of using json_tools:

  1. As a CLI utilty.

  2. As a Python module.

CLI interface

After you’ve installed json_tools you can access it via json command in the shell. It provides a pretty simple yet powerful interface to manipulate JSON documents:

  • print [input_file]

    Pretty-print a JSON file with syntax highlighting and keys sorting.

    If input_file is omitted or equals -, reads JSON from STDIN.

    Example:

    $ echo '{"Hello": ["w", "o", "r", "l", "d", "!"]}' | json print
    {
        "Hello": [
            "w",
            "o",
            "r",
            "l",
            "d",
            "!"
        ]
    }
  • diff [file1] [file2]

    Calculate difference between two JSON documents and output it in JSON patch format.

    Either file1 or file2 can be set to -, in order to read JSON from STDIN.

    Example:

    $ json diff doc1.json doc2.json
    [
        {
            "add": "/lol",
            "value": "wut"
        },
        {
            "remove": "/some/field",
            "prev": {
                "compound": "value"
            }
        }
    ]
  • patch [options] input [patch [patch ...]]

    Modify the JSON file input using a series of JSON patches.

    If patch is omitted or equals -, its content is read from STDIN.

    Options:

    -i, --inplace

    Modify source_file inplace instead of printing it to STDOUT.

Pythonic interface

TBD

Planned features

  1. Support more JSON patch options: currently json_tools only supports add, remove and replace.

  2. Make diff output more human readable (not JSONish).

  3. Improve documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_tools-0.3.1.2.tar.gz (8.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page