# sde
[![PyPI version](https://badge.fury.io/py/sde.svg)](https://badge.fury.io/py/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](https://stackoverflow.com/questions/42716734/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](https://stackoverflow.com/questions/43292243/how-to-modify-a-keys-value-in-a-json-file-from-command-line)
```bash
jq '.address = "abcde"' test.json|sponge test.json
```
Does this seem readable or elegant to you?
How about this instead:
```bash
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
```json
{
"name":"John",
"age":31,
"city":"New York",
"extra": {
"gender": null
}
}
```
### Sample YAML
```yaml
database:
user: example
password: secret
```
### Modify data
```bash
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:
```json
{
"users": [
{
"username": "foo",
"enabled": true
},
{
"username": "bar",
"enabled": true
}
],
}
```
We can set the first user's `enabled` property to `false`:
```bash
sde users.0.enabled false data.json
```
## Installation for CentOS/RHEL 7, 8 or Amazon Linux 2, or Fedora Linux
```bash
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:
```bash
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:
```bash
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.
```bash
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:
```bash
sde -m key sameval file.json
# > exit code 0
sde -m key sameval file.json
# > exit code 2
```
## TODO
### Work with stdin
```bash
echo $json | sde name Jack
```
### Query simple data
```bash
sdg name data.json
```
Raw data
{
"_id": null,
"home_page": "https://github.com/dvershinin/sde",
"name": "sde",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Danila Vershinin",
"author_email": "info@getpagespeed.com",
"download_url": "https://files.pythonhosted.org/packages/07/fd/2feb07b1202bb7dd35a2ef1c91c9b3dcda989ca850f5784c05d2bb060721/sde-1.1.12.tar.gz",
"platform": null,
"description": "# sde\n\n[![PyPI version](https://badge.fury.io/py/sde.svg)](https://badge.fury.io/py/sde)\n\n`sde` is not `sed`. It's a structured data editor for CLI.\n\n## Why?\n\nMany people asked for a simple JSON in-place editing and `jq` was the solution:\n\n* [Modify a key-value in a json using jq in-place](https://stackoverflow.com/questions/42716734/modify-a-key-value-in-a-json-using-jq-in-place)\n* [How to modify a key's value in a JSON file from command line](https://stackoverflow.com/questions/43292243/how-to-modify-a-keys-value-in-a-json-file-from-command-line)\n\n```bash\njq '.address = \"abcde\"' test.json|sponge test.json\n```\n \nDoes this seem readable or elegant to you?\n\nHow about this instead:\n\n```bash\nsde address abcde test.json\n```\n\n`sde` is not a substitute for `jq` or `sed`.\n\nIt allows *simple* in-place JSON/YAML value changes, for *structured* data.\n\n### Sample JSON\n\n```json\n{\n \"name\":\"John\",\n \"age\":31,\n \"city\":\"New York\",\n \"extra\": {\n \"gender\": null\n }\n}\n```\n\n### Sample YAML\n\n```yaml\ndatabase:\n user: example\n password: secret\n```\n\n### Modify data\n\n```bash\nsde name Jack data.json\nsde extra.gender male data.json\nsde database.user john data.yml\n```\n\nIt is possible to modify data in arrays using a dotted notation. Let's take another sample:\n\n```json\n{\n \"users\": [\n {\n \"username\": \"foo\", \n \"enabled\": true\n },\n {\n \"username\": \"bar\", \n \"enabled\": true\n } \n ],\n}\n```\n\nWe can set the first user's `enabled` property to `false`:\n\n```bash\nsde users.0.enabled false data.json\n```\n\n## Installation for CentOS/RHEL 7, 8 or Amazon Linux 2, or Fedora Linux\n\n```bash\nsudo yum -y install https://extras.getpagespeed.com/release-latest.rpm\nsudo yum -y install sde\n```\n \n## Installation for other systems\n\nInstalling with `pip` is easiest:\n\n```bash\npip install sde\n```\n\n## Notes\n\n### Quoting in JSON\n\nQuoting is avoided for `null`, `true`, `false`, and numeric values.\nTo ensure that a given value is quoted, use `-s` (or `--string`) option:\n\n```bash\nsde -s key null file.json\n```\n\n### Force-fail on missing keys\n\nIf you must *edit* the file, by ensuring to update only the existing key, use `-e` (`--must-exist`)\noption. The program will exit without adding the key which doesn't exist.\n\n```bash\nsde -e key val file.json\n```\n\n### Force-fail on unchanged file\n\nIf the data is unchanged after running `sde` (values already match), you can force\na failure exit code `2` by passing the `-m` option:\n\n```bash\nsde -m key sameval file.json\n# > exit code 0\nsde -m key sameval file.json\n# > exit code 2\n```\n\n## TODO\n\n### Work with stdin\n\n```bash\necho $json | sde name Jack\n```\n\n### Query simple data\n\n```bash\nsdg name data.json\n```\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "A CLI tool to edit simple JSON and YAML data files",
"version": "1.1.12",
"project_urls": {
"Homepage": "https://github.com/dvershinin/sde"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8725b6dacccb4ffa9b53d05f2adef0dbab1420f63ce7cc41ff4aa709942bf2f8",
"md5": "924aea6951be643e1a4091822c9aafba",
"sha256": "2d7ed54941f14d291abe7c0b9a15128ce86224282389a3f45a2730adf64cae2c"
},
"downloads": -1,
"filename": "sde-1.1.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "924aea6951be643e1a4091822c9aafba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 9814,
"upload_time": "2024-05-21T06:49:01",
"upload_time_iso_8601": "2024-05-21T06:49:01.056315Z",
"url": "https://files.pythonhosted.org/packages/87/25/b6dacccb4ffa9b53d05f2adef0dbab1420f63ce7cc41ff4aa709942bf2f8/sde-1.1.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "07fd2feb07b1202bb7dd35a2ef1c91c9b3dcda989ca850f5784c05d2bb060721",
"md5": "8f1c8e2be8ed82359f438cc17db7fd59",
"sha256": "3b1a39f686ef92d6c7fe1e0dacb81833620256f2f08fa15e6ad502b8f796913e"
},
"downloads": -1,
"filename": "sde-1.1.12.tar.gz",
"has_sig": false,
"md5_digest": "8f1c8e2be8ed82359f438cc17db7fd59",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11260,
"upload_time": "2024-05-21T06:49:02",
"upload_time_iso_8601": "2024-05-21T06:49:02.205144Z",
"url": "https://files.pythonhosted.org/packages/07/fd/2feb07b1202bb7dd35a2ef1c91c9b3dcda989ca850f5784c05d2bb060721/sde-1.1.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-21 06:49:02",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dvershinin",
"github_project": "sde",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "sde"
}