{"id":19224788,"url":"https://github.com/flipkart-incubator/zjsonpatch","last_synced_at":"2025-05-13T19:06:09.128Z","repository":{"id":23405817,"uuid":"26768047","full_name":"flipkart-incubator/zjsonpatch","owner":"flipkart-incubator","description":"This is an implementation of RFC 6902 JSON Patch written in Java","archived":false,"fork":false,"pushed_at":"2024-12-16T23:40:49.000Z","size":366,"stargazers_count":542,"open_issues_count":41,"forks_count":156,"subscribers_count":63,"default_branch":"master","last_synced_at":"2025-04-26T11:52:14.871Z","etag":null,"topics":["circleci","compaction","java","json","json-document","jsondiff","jsondiffpatch","jsonpatch"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flipkart-incubator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2014-11-17T17:23:43.000Z","updated_at":"2025-04-15T18:45:07.000Z","dependencies_parsed_at":"2023-12-10T12:28:46.912Z","dependency_job_id":"ff09c66a-9e50-47b8-ab4e-b06ecb50506f","html_url":"https://github.com/flipkart-incubator/zjsonpatch","commit_stats":{"total_commits":272,"total_committers":35,"mean_commits":7.771428571428571,"dds":0.5,"last_synced_commit":"a446bf598231c06006d4e3df69b846cdb16d8889"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fzjsonpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fzjsonpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fzjsonpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fzjsonpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipkart-incubator","download_url":"https://codeload.github.com/flipkart-incubator/zjsonpatch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251089406,"owners_count":21534511,"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":["circleci","compaction","java","json","json-document","jsondiff","jsondiffpatch","jsonpatch"],"created_at":"2024-11-09T15:12:51.704Z","updated_at":"2025-04-27T04:40:44.642Z","avatar_url":"https://github.com/flipkart-incubator.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://circleci.com/gh/flipkart-incubator/zjsonpatch/tree/master.svg?style=svg)](https://circleci.com/gh/flipkart-incubator/zjsonpatch/tree/master) [![Join the chat at https://gitter.im/zjsonpatch/community](https://badges.gitter.im/zjsonpatch/community.svg)](https://gitter.im/zjsonpatch/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge) \n\n# This is an implementation of  [RFC 6902 JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902) written in Java.\n\n## Description \u0026 Use-Cases\n- Java Library to find / apply JSON Patches according to [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).\n- JSON Patch defines a JSON document structure for representing changes to a JSON document.\n- It can be used to avoid sending a whole document when only a part has changed, thus reducing network bandwidth requirements if data (in JSON format) is required to send across multiple systems over network or in case of multi DC transfer.\n- When used in combination with the HTTP PATCH method as per [RFC 5789 HTTP PATCH](https://datatracker.ietf.org/doc/html/rfc5789), it will do partial updates for HTTP APIs in a standard  way.\n\n\n### Compatible with : Java 7+ versions\n\n## Code Coverage\nPackage      |\tClass, % \t |  Method, % \t   |  Line, %           |\n-------------|---------------|-----------------|--------------------|\nall classes  |\t100% (6/ 6)  |\t93.6% (44/ 47) |  96.2% (332/ 345)  |\n\n## Complexity\n- To find JsonPatch : Ω(N+M) ,N and M represents number of keys in first and second json respectively / O(summation of la*lb) where la , lb represents JSON array of length la / lb of against same key in first and second JSON ,since LCS is used to find difference between 2 JSON arrays there of order of quadratic.\n- To Optimize Diffs ( compact move and remove into Move ) : Ω(D) / O(D*D) where D represents number of diffs obtained before compaction into Move operation.\n- To Apply Diff : O(D) where D represents number of diffs\n\n### How to use:\n\n### Current Version : 0.4.16\n\nAdd following to `\u003cdependencies/\u003e` section of your pom.xml -\n\n```xml\n\u003cgroupId\u003ecom.flipkart.zjsonpatch\u003c/groupId\u003e\n\u003cartifactId\u003ezjsonpatch\u003c/artifactId\u003e\n\u003cversion\u003e{version}\u003c/version\u003e\n```\n- Available on [maven central repository](http://search.maven.org/#search%7Cga%7C1%7Cg%3Acom.flipkart.zjsonpatch%20a%3Azjsonpatch)\n\n## API Usage\n\n### Obtaining JSON Diff as patch\n```xml\nJsonNode patch = JsonDiff.asJson(JsonNode source, JsonNode target)\n```\nComputes and returns a JSON `patch` from `source`  to `target`,\nBoth `source` and `target` must be either valid JSON objects or arrays or values. \nFurther, if resultant `patch` is applied to `source`, it will yield `target`.\n\nThe algorithm which computes this JsonPatch currently generates following operations as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902#section-4) - \n - `add`\n - `remove`\n - `replace`\n - `move`\n - `copy`\n\n### Apply Json Patch\n```xml\nJsonNode target = JsonPatch.apply(JsonNode patch, JsonNode source);\n```\nGiven a `patch`, it apply it to `source` JSON and return a `target` JSON which can be ( JSON object or array or value ). This operation  performed on a clone of `source` JSON ( thus, the `source` JSON is unmodified and can be used further). \n\n## To turn off MOVE \u0026 COPY Operations\n```xml\nEnumSet\u003cDiffFlags\u003e flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone()\nJsonNode patch = JsonDiff.asJson(JsonNode source, JsonNode target, flags)\n```\n\n### Example\nFirst Json\n```json\n{\"a\": 0,\"b\": [1,2]}\n```\n\nSecond json ( the json to obtain )\n```json\n {\"b\": [1,2,0]}\n```\nFollowing patch will be returned:\n```json\n[{\"op\":\"move\",\"from\":\"/a\",\"path\":\"/b/2\"}]\n```\nhere `\"op\"` specifies the operation (`\"move\"`), `\"from\"` specifies the path from where the value should be moved, and  `\"path\"` specifies where value should be moved. The value that is moved is taken as the content at the `\"from\"` path.\n\n### Apply Json Patch In-Place\n```xml\nJsonPatch.applyInPlace(JsonNode patch, JsonNode source);\n```\nGiven a `patch`, it will apply it to the `source` JSON mutating the instance, opposed to `JsonPatch.apply` which returns \na new instance with the patch applied, leaving the `source` unchanged.\n\nThis is an extension to the RFC, and has some additional limitations. Specifically, the source document cannot be fully change in place (the Jackson APIs do not support that level of mutability). This means the following operations are not supported:\n* `remove` with an empty or root path;\n* `replace` with an empty or root path;\n* `move`, `add` or `copy` targeting an empty or root path. \n\n### Tests:\n1. 100+ selective hardcoded different input JSONs , with their driver test classes present under /test directory.\n2. Apart from selective input, a deterministic random JSON generator is present under ( TestDataGenerator.java ),  and its driver test class method is JsonDiffTest.testGeneratedJsonDiff().\n\n\n#### *** Tests can only show presence of bugs and not their absence ***\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipkart-incubator%2Fzjsonpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipkart-incubator%2Fzjsonpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipkart-incubator%2Fzjsonpatch/lists"}