{"id":18691058,"url":"https://github.com/ffissore/json-patch-optimizer","last_synced_at":"2025-11-08T09:30:29.639Z","repository":{"id":145833716,"uuid":"208824648","full_name":"ffissore/json-patch-optimizer","owner":"ffissore","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-15T23:31:18.000Z","size":17,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T02:43:34.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ffissore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-16T14:46:09.000Z","updated_at":"2020-10-14T06:48:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"b981e0b6-ac5a-42da-be10-bd5d30e7d30c","html_url":"https://github.com/ffissore/json-patch-optimizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffissore%2Fjson-patch-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffissore%2Fjson-patch-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffissore%2Fjson-patch-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffissore%2Fjson-patch-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ffissore","download_url":"https://codeload.github.com/ffissore/json-patch-optimizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239550272,"owners_count":19657541,"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","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":[],"created_at":"2024-11-07T10:53:04.661Z","updated_at":"2025-11-08T09:30:29.494Z","avatar_url":"https://github.com/ffissore.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![security status](https://www.meterian.com/badge/gh/ffissore/json-patch-optimizer/security)](https://www.meterian.com/report/gh/ffissore/json-patch-optimizer)\n[![stability status](https://www.meterian.com/badge/gh/ffissore/json-patch-optimizer/stability)](https://www.meterian.com/report/gh/ffissore/json-patch-optimizer)\n\n# JSON Patch Optimizer\n\nA java library and command line program that takes a JSON patch and reduces it to a smaller form.\n\nExample:\n```json \n[\n  {\n    \"op\": \"add\",\n    \"path\": \"/foo\",\n    \"value\": \"bar\"\n  },\n  {\n    \"op\": \"add\",\n    \"path\": \"/bar\",\n    \"value\": \"baz\"\n  },\n  {\n    \"op\": \"remove\",\n    \"path\": \"/foo\"\n  }\n]\n```\n\nbecomes\n\n```json\n[\n  {\n    \"op\": \"add\",\n    \"path\": \"/bar\",\n    \"value\": \"baz\"\n  }\n]\n```\n\nbecause the third operation negates the first one.\n\n### Usage\n\n#### As a java library\n\nLoad the JSON patch into an `ArrayNode` instance, then pass that instance to `JsonPatchOptimizer.optimize` method. Example:\n\n```java\nFile jsonPatchFile = ...\nArrayNode jsonPatch = (ArrayNode) new ObjectMapper().readTree(jsonPatchFile);\nArrayNode optimizedJsonPatch = new JsonPatchOptimizer().optimize(patch, false);\n\n// if you want test operations added\nArrayNode optimizedJsonPatch = new JsonPatchOptimizer().optimize(patch, true);\n```\n\n#### As a command line utility\n\nFirst build the project with `mvn clean package assembly:single` then use it like so:\n\n```bash\njava -jar target/json-patch-optimizer-1.0-SNAPSHOT-jar-with-dependencies.jar \u003cPATH TO FILE\u003e \u003ctrue|false if you want test operations\u003e \n```\n\n#### As a command line utility from Docker\n\nPull the the image and run it, like so:\n\n```bash\ndocker pull ffissore/json-patch-optimizer\ndocker run --rm -it -v \u003cPATH TO FILE\u003e:/file.json ffissore/json-patch-optimizer /file.json \u003ctrue|false if you want test operations\u003e\n```\n\n### Optimizations\n\nThis table shows how two subsequent operations are optimized\n\n| Previous operation | Current operation | Optimize to                  |\n|--------------------|-------------------|------------------------------|\n| none               | add               | no changes                   |\n| add                | add               | add new value                |\n| add                | remove            | delete both                  |\n| add                | replace           | add replaced value           |\n| add                | copy              | copy                         |\n| add                | move              | move                         |\n| none               | remove            | no changes                   |\n| remove             | add               | replace                      |\n| remove             | remove            | ignore                       |\n| remove             | replace           | replace                      |\n| remove             | copy              | copy                         |\n| remove             | move              | move                         |\n| none               | replace           | replace                      |\n| replace            | add               | error                        |\n| replace            | remove            | remove                       |\n| replace            | replace           | replace new value            |\n| replace            | copy              | copy                         |\n| replace            | move              | move                         |\n| none               | copy              | copy                         |\n| copy               | add               | add                          |\n| copy               | remove            | delete both                  |\n| copy               | replace           | add                          |\n| copy               | copy              | update 'from'                |\n| copy               | move              | move                         |\n| none               | move              | move                         |\n| move               | add               | add                          |\n| move               | remove            | delete 'from'                |\n| move               | replace           | delete 'from', add new value |\n| move               | copy              | copy                         |\n| move               | move              | merge in one move            |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffissore%2Fjson-patch-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fffissore%2Fjson-patch-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffissore%2Fjson-patch-optimizer/lists"}