Skip to main content

jse - JSON Editor PyPi build status codecov

quickly edit json files from the command line

jse is pragmatic and terse. It lets you edit json fast, without needing to care about quotes, types, exact indexes, or any of the stuff that makes json a pain.

Usage

$ jse FILE COMMAND QUERY VALUE

TLDR Version

edit an existing key: e or edit

$ jse config.json edit app.version 0.3.3

add a new element: a or add

$ jse todo.json add list.shopping {task:eggs,done:false}

delete a value: d or delete

$ jse problems.json delete problems[99]

full examples with json files below

Installing

pip3 install jse

Running from Source

Requirements:

Steps:

  1. clone the repository
  2. install click pip3 install click
  3. make the run script executable chmod +x run.py
  4. place jse on the path ln -s /path/to/run.py ~/.local/bin/jse

Using poetry is recommended if you plan to contribute

$ pip3 install poetry
$ poetry install
$ poetry shell

Examples

Assume this json file is in the current directory

# example.json
{
    "users": [
        {"name": "alice", "age": 21, "admin": false},
        {"name": "bob", "age": 57, "admin": true},
        {"name": "charlie", "age": 37, "admin": false}
    ]
}

To delete the user alice using jse, all we need to do is specify d or delete mode and the path to her user object

$ jse example.json d users[0]

We can use both index or dot notation.

$ jse example.json d users.0   #users.first or users.^ also work
# example.json
{
    "users": [
        {"name": "bob", "age": 57, "admin": true},
        {"name": "charlie", "age": 37, "admin": false}
    ]
}

Now lets make charlie an admin. To edit an existing field, use the edit command with e or edit. Edit takes a key to change and its new value.

$ jse example.json e users.1.admin true
# example.json
{
    "users": [
        {"name": "bob", "age": 57, "admin": true},
        {"name": "charlie", "age": 37, "admin": true}
    ]
}

jse is smart enough to infer datatypes from the command line. it can also accept complex nested objects and arrays in a terse, quote-free format. Lets add a new nested field to the file with add or a

$ jse example.json a highscore [{score:32.5,user:bob,metadata:{ip:192.168.1.102,client:firefox}}]
{
  "users": [
    { "name": "bob", "age": 57, "admin": true },
    { "name": "charlie", "age": 37, "admin": true }
  ],
  "highscore": [
    {
      "score": 32.5,
      "user": "bob",
      "metadata": {
        "ip": "192.168.1.102",
        "client": "firefox"
      }
    }
  ]
}

jse also understands lists, so you can add new elements to one without needing an explicit index. It will infer we are trying to append from add instead of changing the list itself to an object (edit)

$ jse example.json a highscore {score:52,user:charlie}
{
  "users": [
    { "name": "bob", "age": 57, "admin": true },
    { "name": "charlie", "age": 37, "admin": true }
  ],
  "highscore": [
    {
      "score": "32.5",
      "user": "bob",
      "metadata": {
        "ip": "192.168.1.102",
        "client": "firefox"
      }
    },
    {
      "score": 52.0,
      "user": "charlie"
    }
  ]
}

first and last (or ^ and $) can also be used as a list index for any operation

$ jse example.json a users.first {name:jon,age:22,admin:false}
{
  "users": [
    { "name": "jon", "age": 22, "admin": false },
    { "name": "bob", "age": 57, "admin": true },
    { "name": "charlie", "age": 37, "admin": true }
  ],
  "highscore": [
    {
      "score": "32.5",
      "user": "bob",
      "metadata": {
        "ip": "192.168.1.102",
        "client": "firefox"
      }
    },
    {
      "score": 52.0,
      "user": "charlie"
    }
  ]
}

jse's error messages are informative, because no one wants a generic KeyError

$ jse example.json a users.0.name "not bob"
'name' already has a value. Use the edit command to modify it
$ jse example.json d users[2]
There is no element with index 2. The largest index is 1

You can also delete mulitple keys in one command `` $ jse example.json d users.0.age users.1.age users.2.age

```json
{
    "users": [
        {
            "name": "jon",
            "admin": false,
        },
        {
            "name": "bob",
            "admin": true,
        },
        {
            "name": "charlie",
            "admin": true
        }
    ]
    ...
}

No need to specify every element, just use the * or all operator

$ jse example.json d users.*.age # or users.all.age

Metadata

Release files for jse 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jse 0.1.4
File Size Uploaded
jse-0.1.4.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jse 0.1.4
File Interpreter ABI Platform
jse-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 41.2 kB

Release files / jse-0.1.4.tar.gz

Download URL jse-0.1.4.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8d7341ff03da85d29fcda18dc77c48810e86e9e97eda16e4e64a7a65441a5381
BLAKE2b-256 checksum
How to use checksums
026b0cca2b480884256f1ccbdf88b059ba6711ce8eb09287a0b614f7dbad2c26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

Release files / jse-0.1.4-py3-none-any.whl

Download URL jse-0.1.4-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ae37b56086ce27dbcf6eea42c7a22364b955cecb6972e3770a23b008388b0bc
BLAKE2b-256 checksum
How to use checksums
1705a53420cca1b222cba7178d5d75e18865d18b548126b9e7cace5918a39f8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page