https://github.com/jelchison/sort-json
Python script that sorts a JSON object according to its keys. Useful for diff'ing two JSON files.
https://github.com/jelchison/sort-json
compare deterministic diff json python python2 serialize sort
Last synced: 11 months ago
JSON representation
Python script that sorts a JSON object according to its keys. Useful for diff'ing two JSON files.
- Host: GitHub
- URL: https://github.com/jelchison/sort-json
- Owner: JElchison
- License: gpl-3.0
- Created: 2017-11-18T19:00:59.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-09-10T11:13:55.000Z (over 5 years ago)
- Last Synced: 2025-02-01T15:45:56.542Z (about 1 year ago)
- Topics: compare, deterministic, diff, json, python, python2, serialize, sort
- Language: Python
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sort-json
Python script that sorts a JSON object according to its keys.
The product of this script is deterministic, so this is useful for diff'ing two JSON files.
## Example Usage
Sort a JSON file:
```
user@computer:~$ cat abc.json
{
"c": 0,
"b": 0,
"a": {
"a3": 1,
"a2": 2,
"a1": 3
}
}
user@computer:~$ ./sort-json.py abc.json
{
"a": {
"a1": 3,
"a2": 2,
"a3": 1
},
"b": 0,
"c": 0
}
```
Diff two JSON files:
```
user@computer:~$ cat abcd.json
{
"d": 0,
"c": 0,
"b": 0,
"a": {
"a3": 1,
"a2": 2,
"a1": 3
}
}
user@computer:~$ diff <(./sort-json.py abc.json) <(./sort-json.py abcd.json)
8c8,9
< "c": 0
---
> "c": 0,
> "d": 0
```
## References
* https://docs.python.org/2/library/json.html#json.dump