{"id":34075513,"url":"https://github.com/k3a/struct_diff","last_synced_at":"2026-05-06T09:34:00.518Z","repository":{"id":59617853,"uuid":"535094673","full_name":"k3a/struct_diff","owner":"k3a","description":"Structural diff for JSON, YAML and other similar structures","archived":false,"fork":false,"pushed_at":"2022-10-26T19:43:51.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T01:02:55.396Z","etag":null,"topics":["comparison","diff","json","library","object","python","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/k3a.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-10T19:11:03.000Z","updated_at":"2025-02-24T14:30:23.000Z","dependencies_parsed_at":"2022-09-25T13:37:21.247Z","dependency_job_id":null,"html_url":"https://github.com/k3a/struct_diff","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/k3a/struct_diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k3a%2Fstruct_diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k3a%2Fstruct_diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k3a%2Fstruct_diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k3a%2Fstruct_diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k3a","download_url":"https://codeload.github.com/k3a/struct_diff/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k3a%2Fstruct_diff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27725292,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-14T02:00:11.348Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["comparison","diff","json","library","object","python","yaml"],"created_at":"2025-12-14T09:48:45.754Z","updated_at":"2025-12-14T09:48:49.995Z","avatar_url":"https://github.com/k3a.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# struct_diff\n\nCopares two objects and produces a dictionary describing changes.\nIdeal for comparing two JSON or YAML objects and generating a structural human-readable diff.\n\nThis is a Python port of [json-diff](https://github.com/andreyvit/json-diff) JavaScript library.\n\n## Purpose\n\nIt produces diff like this:\n\n```json\n{\n  \"type__deleted\": \"donut\",\n  \"name\": {\n    \"__old\": \"Cake\",\n    \"__new\": \"Donut\"\n  },\n  \"arr\": [\n    [\n      \" \"\n    ],\n    [\n      \"-\",\n      2\n    ],\n    [\n      \"+\",\n      {\n        \"obj\": \"ok\",\n        \"secondkey\": 123\n      }\n    ],\n    [\n      \" \"\n    ],\n    [\n      \"+\",\n      4\n    ]\n  ],\n  ... shortened ...\n}\n```\n\nand from that it can generate a human-readable structural JSON diff:\n\n```diff\n {\n-  type: \"donut\"\n-  name: \"Cake\"\n+  name: \"Donut\"\n   arr: [\n     ...\n-    2\n+    {\n+      obj: \"ok\"\n+      secondkey: 123\n+    }\n     ...\n+    4\n   ]\n   image: {\n     caption: {\n-      width: 123\n+      width: 321\n-      height: 321\n+      height: {\n+        value: 642\n+        units: \"mm\"\n+      }\n     }\n   }\n   thumbnail: {\n+    extra: {\n+      price: 111\n+      sizes: [\n+        \"L\"\n+        \"XL\"\n+      ]\n+    }\n-    width: 32\n+    width: 64\n   }\n }\n```\n\nor structural YAML diff:\n\n```diff\n-  type: \"donut\"\n-  name: \"Cake\"\n+  name: \"Donut\"\n   arr: \n     ...\n-    - 2\n+    - obj: \"ok\"\n+      secondkey: 123\n     ...\n+    - 4\n   image: \n     caption: \n-      width: 123\n+      width: 321\n-      height: 321\n+      height: \n+        value: 642\n+        units: \"mm\"\n   thumbnail: \n+    extra: \n+      price: 111\n+      sizes: \n+        - \"L\"\n+        - \"XL\"\n-    width: 32\n+    width: 64\n```\n\n## CLI Usage\n\nSimple:\n\n```python3 -m struct_diff a.json b.json```\n\nDetailed:\n\n```txt\n% python3 -m struct_diff -h\n\nusage: struct_diff [-h] [-C] [--no-color] [-j] [-Y] [-f] [--max-elisions MAX_ELISIONS] [-o KEY [KEY ...]] [-n] [-s] [-c] [-k] [-K] [-p DECIMALS] [-w INDENT_WIDTH] old new\n\npositional arguments:\n  old                   original file\n  new                   new file\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -C                    force colorize the output\n  --no-color            do not colorize the output\n  -j, --raw-json        display raw JSON encoding of the diff\n  -Y, --yaml            output diff as YAML\n  -f, --full            include the equal sections of the document, not just the deltas\n  --max-elisions MAX_ELISIONS\n                        max number of ...'s to show in a row in \"deltas\" mode (before collapsing them) #var(maxElisions)\n  -o KEY [KEY ...], --output-keys KEY [KEY ...]\n                        always print this comma separated keys, with their value, if they are part of an object with any diff\n  -n, --output-new-only\n                        output only the updated and new key/value pairs (without marking them as such). If you need only the diffs from the old file, just exchange the first and second json\n  -s, --sort            sort primitive values in arrays before comparing\n  -c, --object-context  if a scalar value of an object key is changed, also include other (unchanged) values of that object\n  -k, --keys-only       compare only the keys, ignore the differences in values\n  -K, --keep-unchanged-values\n                        instead of omitting values that are equal, output them as they are\n  -p DECIMALS, --precision DECIMALS\n                        round all floating point numbers to this number of decimal places prior to comparison\n  -w INDENT_WIDTH, --indent-width INDENT_WIDTH\n                        number of spaces for indendation\n```\n\n## Library Usage\n\n```py\n\u003e\u003e\u003e from struct_diff import Comparator, YAMLFormatter\n\u003e\u003e\u003e d = diff({'a':'first'}, {'b': 'second'})\n\u003e\u003e\u003e f = YAMLFormatter(d, {'max_elisions': 1})\n\u003e\u003e\u003e print(f)\n- a: first\n+ b: second\n```\n\n## Things to do\n\n- add unit tests\n\n## Contributing\n\nIt is currently good enough for me so I don't intend to spend much more time on it.\nYou are welcome to implement stuff from `Things to do` or more and submit pull requests.\n\n## Change Log\n\n- 0.9.0-4,5,6,7 PyPI releases with bugfixes\n- 0.9.0-3 Added object-context option to include unchanged values in an object with a changed scalar value\n- 0.9.0-2 Multi-line unified diff for strings in YAML mode\n- 0.9.0-1 Implements mixed sorting (numerical sort first, alphanumerical string sort next)\n- 0.9.0 The first complete port of json-diff JS library with all the functionality\n\n## Credits\n\n- [json-diff](https://github.com/andreyvit/json-diff) - the original javascript implementation\n\nReleased under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk3a%2Fstruct_diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk3a%2Fstruct_diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk3a%2Fstruct_diff/lists"}