Package: jse
jse - JSON Editorquickly edit json files from the command linejse 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 VALUETLDR Versionedit an existing key:eoredit$ jse config.json edit app.version 0.3.3add a new element:aoradd$ jse todo.json add list.shopping {task:eggs,done:false}delete a value:dordelete$ jse problems.json delete problems[99]fullexamples with json filesbelowInstallingpip3 install jseRunning from SourceRequirements:Python 3.7+ClickSteps:clone the repositoryinstall clickpip3 install clickmake the run script executablechmod +x run.pyplace jse on the pathln -s /path/to/run.py ~/.local/bin/jseUsing poetry is recommended if you plan to contribute$pip3installpoetry
$poetryinstall
$poetryshellExamplesAssume 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 specifydordeletemode and the path to heruserobject$ jse example.json d users[0]We can use both index or dot notation.$jseexample.jsondusers.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 witheoredit. 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 withaddora$ 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 fromaddinstead 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 1You 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*oralloperator$jseexample.jsondusers.*.age# or users.all.age