A CLI tool to edit simple JSON and YAML data files
Project description
sde
sde
is not sed
. It's a structured data editor for CLI.
Why?
Many people asked for a simple JSON in-place editing and jq
was the solution:
- Modify a key-value in a json using jq in-place
- How to modify a key's value in a JSON file from command line
jq '.address = "abcde"' test.json|sponge test.json
Does this seem readable or elegant to you?
sde
is not a substitute for jq
or sed
.
It allows simple in-place JSON/YAML value changes, for simple data.
Sample JSON
{
"name":"John",
"age":31,
"city":"New York",
"extra": {
"gender": null
}
}
Sample YAML
database:
user: example
password: secret
Modify data
sde name Jack data.json
sde extra.gender male data.json
sde database.user john data.yml
It is possible to modify data in arrays, e.g.:
{
"users": [
{
"username": "foo",
"enabled": true
},
{
"username": "bar",
"enabled": true
}
],
}
Set the first user's enabled
property to false
:
sde users.0.enabled false data.json
Installation for CentOS/RHEL 7, 8 or Amazon Linux 2
sudo yum -y install https://extras.getpagespeed.com/release-latest.rpm
sudo yum -y install sde
Installation for other systems
Installing with pip
is easiest:
pip install sde
Notes
Quoting is avoided for null
, true
, false
, and numeric values.
To ensure that a given value is quoted, use -s
(or --string
) option:
sde -s key null file.json
If you must edit the file, by ensuring to update only the existing key, use -e
(--must-exist
)
option. The program will exit without adding the key which doesn't exist.
sde -e key val file.json
TODO
Work with stdin
echo $json | sde name Jack
Query simple data
sdg name data.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.