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?

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


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.6.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

sde-1.1.6-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sde-1.1.6.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for sde-1.1.6.tar.gz
Algorithm Hash digest
SHA256 5a942f2c6b338ccd04b3abd2f3c1babc78278c945c72c95ed179ede160636c47
MD5 ceb3fe6a9e09afc1bf6fcef345412e54
BLAKE2b-256 371d5b4bf4bd645344881b859cf3b0e8e1d25d45032ac63d689619dda154d708

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sde-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for sde-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 678459722d80adaa54590f91ad4b8ff13dca485a2f8b3dc37f6536b0a4224ea4
MD5 2c85849359d66d596590f9c672ff8645
BLAKE2b-256 7daf3764ed24172de84b3718077690e0b5209ecab81abb94abdb67663d399e03

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