Skip to main content

A CLI tool to edit simple JSON and YAML data files

Project description

sde

PyPI version

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:

jq '.address = "abcde"' test.json|sponge test.json

Does this seem readable or elegant to you?

How about this instead:

sde address abcde test.json

sde is not a substitute for jq or sed.

It allows simple in-place JSON/YAML value changes, for structured 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 using a dotted notation. Let's take another sample:

{
    "users": [
        {
            "username": "foo", 
            "enabled": true
        },
        {
            "username": "bar", 
            "enabled": true
        }      
    ],
}

We can 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, or Fedora Linux

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 in JSON

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

Force-fail on missing keys

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

Force-fail on unchanged file

If the data is unchanged after running sde (values already match), you can force a failure exit code 2 by passing the -m option:

sde -m key sameval file.json
# > exit code 0
sde -m key sameval file.json
# > exit code 2

TODO

Work with stdin

echo $json | sde name Jack

Query simple data

sdg name data.json

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

sde-1.1.9.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

sde-1.1.9-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file sde-1.1.9.tar.gz.

File metadata

  • Download URL: sde-1.1.9.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for sde-1.1.9.tar.gz
Algorithm Hash digest
SHA256 f47acabe0a001304d92fbc49a89ca9bf1df8537577a2b102400ef122254286af
MD5 4c58b1abeb181925189fc0a59bcd1ae5
BLAKE2b-256 0d9ae84d0251dbc44ea6878f632f555055b573d1947b6efda076a6fa6627debf

See more details on using hashes here.

File details

Details for the file sde-1.1.9-py3-none-any.whl.

File metadata

  • Download URL: sde-1.1.9-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for sde-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b97b4d9209c157b26c54bb71a837b851def518573a9de08d4993528e5d96123c
MD5 1ebc04c7b55d2797109a3bececbac531
BLAKE2b-256 a909ab414eee0b09955fdc617a2c2ff5f065c9cbade201e535e21519e4ae40e9

See more details on using hashes here.

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