Skip to main content

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

Release files for sde 1.1.12

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

Source distribution (sdist)

Source distribution for sde 1.1.12
File Size Uploaded
sde-1.1.12.tar.gz 11.3 kB Details

Built distribution (wheel)

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

Total release size: 21.1 kB

Release files / sde-1.1.12.tar.gz

Download URL sde-1.1.12.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3b1a39f686ef92d6c7fe1e0dacb81833620256f2f08fa15e6ad502b8f796913e
BLAKE2b-256 checksum
How to use checksums
07fd2feb07b1202bb7dd35a2ef1c91c9b3dcda989ca850f5784c05d2bb060721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release files / sde-1.1.12-py3-none-any.whl

Download URL sde-1.1.12-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d7ed54941f14d291abe7c0b9a15128ce86224282389a3f45a2730adf64cae2c
BLAKE2b-256 checksum
How to use checksums
8725b6dacccb4ffa9b53d05f2adef0dbab1420f63ce7cc41ff4aa709942bf2f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.1.12 This release

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.3

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