{"id":24957117,"url":"https://github.com/deblockt/json-diff","last_synced_at":"2026-01-06T20:28:11.126Z","repository":{"id":57732965,"uuid":"348346540","full_name":"deblockt/json-diff","owner":"deblockt","description":"A library to generate a json diff on java","archived":false,"fork":false,"pushed_at":"2024-07-19T06:40:12.000Z","size":135,"stargazers_count":46,"open_issues_count":3,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T11:04:53.744Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deblockt.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-16T12:52:50.000Z","updated_at":"2025-07-04T15:11:22.000Z","dependencies_parsed_at":"2024-04-21T14:37:16.309Z","dependency_job_id":"44b04c0f-3df9-44f5-9ea3-73c8bc835963","html_url":"https://github.com/deblockt/json-diff","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/deblockt/json-diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deblockt%2Fjson-diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deblockt%2Fjson-diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deblockt%2Fjson-diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deblockt%2Fjson-diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deblockt","download_url":"https://codeload.github.com/deblockt/json-diff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deblockt%2Fjson-diff/sbom","scorecard":{"id":331153,"data":{"date":"2025-08-11","repo":{"name":"github.com/deblockt/json-diff","commit":"56a38af36423027e254c56a59903064bf5440535"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.6,"checks":[{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: gradle/wrapper/gradle-wrapper.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":6,"reason":"dependency not pinned by hash detected -- score normalized to 6","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/deblockt/json-diff/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/deblockt/json-diff/publish.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/deblockt/json-diff/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/deblockt/json-diff/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/deblockt/json-diff/test.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   4 out of   5 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Token-Permissions","score":9,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/publish.yml:12","Warn: jobLevel 'packages' permission set to 'write': .github/workflows/publish.yml:13","Warn: no topLevel permission defined: .github/workflows/publish.yml:1","Info: topLevel 'contents' permission set to 'read': .github/workflows/test.yml:7"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T03:40:17.290Z","repository_id":57732965,"created_at":"2025-08-18T03:40:17.290Z","updated_at":"2025-08-18T03:40:17.290Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272959411,"owners_count":25022056,"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-08-31T02:00:09.071Z","response_time":79,"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":[],"created_at":"2025-02-03T06:54:35.822Z","updated_at":"2026-01-06T20:28:11.119Z","avatar_url":"https://github.com/deblockt.png","language":"Java","readme":"# Java json-diff\n\nA customizable library to perform JSON comparisons with detailed diff output.\n\n## Why Use json-diff?\n\nThis library provides:\n\n- **Readable diffs** between two JSON documents\n- **Similarity scoring** (0-100) to compare multiple JSON documents and find the most similar ones\n- **Fully customizable** comparison modes (strict, lenient, or mixed) with easy-to-create custom matchers\n- **Multiple output formats** (patch file, text) with the ability to create custom formatters\n\n## Installation\n\n**Maven:**\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.deblockt\u003c/groupId\u003e\n    \u003cartifactId\u003ejson-diff\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**Gradle:**\n```gradle\nimplementation 'io.github.deblockt:json-diff:2.0.0'\n```\n\n\u003e **Note:** Version 2.0.0 requires Java 21+ and uses Jackson 3.x\n\n## Quick Start\n\n```java\nfinal var expectedJson = \"{\\\"name\\\": \\\"John\\\", \\\"age\\\": 30, \\\"city\\\": \\\"Paris\\\"}\";\nfinal var receivedJson = \"{\\\"name\\\": \\\"Jane\\\", \\\"age\\\": 30, \\\"country\\\": \\\"France\\\"}\";\n\n// Define your matcher\nfinal var jsonMatcher = new CompositeJsonMatcher(\n    new LenientJsonArrayPartialMatcher(),\n    new LenientJsonObjectPartialMatcher(),\n    new StrictPrimitivePartialMatcher()\n);\n\n// Generate the diff\nfinal var diff = DiffGenerator.diff(expectedJson, receivedJson, jsonMatcher);\n\n// Display errors\nSystem.out.println(OnlyErrorDiffViewer.from(diff));\n\n// Get similarity score (0-100)\nSystem.out.println(\"Similarity: \" + diff.similarityRate() + \"%\");\n```\n\nOutput:\n```\nThe property \"$.city\" is not found\nThe property \"$.name\" didn't match. Expected \"John\", Received: \"Jane\"\n\nSimilarity: 50.0%\n```\n\n## Output Formats\n\n### Error List (OnlyErrorDiffViewer)\n\n```java\nfinal var errors = OnlyErrorDiffViewer.from(diff);\nSystem.out.println(errors);\n```\n\nOutput:\n```\nThe property \"$.city\" is not found\nThe property \"$.name\" didn't match. Expected \"John\", Received: \"Jane\"\n```\n\n### Patch Format (PatchDiffViewer)\n\n```java\nfinal var patch = PatchDiffViewer.from(diff);\nSystem.out.println(patch);\n```\n\nOutput:\n```diff\n--- actual\n+++ expected\n@@ @@\n {\n   \"age\": 30,\n+  \"city\": \"Paris\",\n-  \"country\": \"France\",\n-  \"name\": \"Jane\",\n+  \"name\": \"John\"\n }\n```\n\n## Comparison Modes\n\n`CompositeJsonMatcher` accepts multiple matchers that handle different JSON types. The order matters: the first matcher that can handle a comparison will be used.\n\n### Strict Mode\n\nRequires exact matches:\n\n```java\nfinal var strictMatcher = new CompositeJsonMatcher(\n    new StrictJsonArrayPartialMatcher(),  // Same items in same order\n    new StrictJsonObjectPartialMatcher(), // Same properties, no extras\n    new StrictPrimitivePartialMatcher()   // Exact type and value match\n);\n```\n\n### Lenient Mode\n\nIgnores extra properties and array order:\n\n```java\nfinal var lenientMatcher = new CompositeJsonMatcher(\n    new LenientJsonArrayPartialMatcher(),  // Ignores array order and extra items\n    new LenientJsonObjectPartialMatcher(), // Ignores extra properties\n    new LenientNumberPrimitivePartialMatcher(), // 10.0 == 10\n    new StrictPrimitivePartialMatcher()        // Other primitives\n);\n```\n\n### Mixed Mode\n\nYou can combine matchers for custom behavior:\n\n```java\nfinal var mixedMatcher = new CompositeJsonMatcher(\n    new LenientJsonArrayPartialMatcher(),  // Lenient on arrays\n    new StrictJsonObjectPartialMatcher(),  // Strict on objects\n    new StrictPrimitivePartialMatcher()\n);\n```\n\n## Available Matchers\n\n### Array Matchers\n\n| Matcher | Description |\n|---------|-------------|\n| `LenientJsonArrayPartialMatcher` | Ignores array order and extra items |\n| `StrictJsonArrayPartialMatcher` | Requires same items in same order |\n\n### Object Matchers\n\n| Matcher | Description |\n|---------|-------------|\n| `LenientJsonObjectPartialMatcher` | Ignores extra properties in received JSON |\n| `StrictJsonObjectPartialMatcher` | Requires exact same properties |\n\n### Primitive Matchers\n\n| Matcher | Description |\n|---------|-------------|\n| `StrictPrimitivePartialMatcher` | Exact type and value match |\n| `LenientNumberPrimitivePartialMatcher` | Numbers are equal if values match (`10.0 == 10`) |\n\n### Special Matchers\n\n| Matcher | Description |\n|---------|-------------|\n| `NullEqualsEmptyArrayMatcher` | Treats `null` and `[]` as equivalent |\n| `IgnoredPathMatcher` | Ignores specified fields during comparison |\n\n## Treating Null as Empty Array\n\nThe `NullEqualsEmptyArrayMatcher` allows you to consider `null` values and empty arrays `[]` as equivalent. This is useful when different systems represent \"no data\" differently.\n\n```java\nfinal var jsonMatcher = new CompositeJsonMatcher(\n    new NullEqualsEmptyArrayMatcher(),     // Must be first to handle null vs []\n    new LenientJsonArrayPartialMatcher(),\n    new LenientJsonObjectPartialMatcher(),\n    new StrictPrimitivePartialMatcher()\n);\n\n// These will match with 100% similarity:\n// {\"items\": null}  vs  {\"items\": []}\n// {\"items\": []}    vs  {\"items\": null}\n\nfinal var diff = DiffGenerator.diff(\n    \"{\\\"items\\\": null}\",\n    \"{\\\"items\\\": []}\",\n    jsonMatcher\n);\n\nSystem.out.println(diff.similarityRate()); // 100.0\n```\n\n**Important:**\n- Place `NullEqualsEmptyArrayMatcher` **before** other matchers in the constructor\n- This matcher only handles `null` vs empty array `[]`, not missing properties\n- Non-empty arrays do not match `null`\n\n## Ignoring path\n\nThe `IgnoredPathMatcher` allows you to ignore specific fields during comparison. This is useful for fields like timestamps, IDs, or other dynamic values that you don't want to compare.\n\n```java\nfinal var jsonMatcher = new CompositeJsonMatcher(\n    new IgnoredPathMatcher(\"timestamp\", \"id\"),  // Must be first\n    new LenientJsonArrayPartialMatcher(),\n    new LenientJsonObjectPartialMatcher(),\n    new StrictPrimitivePartialMatcher()\n);\n\n// These will match with 100% similarity:\nfinal var diff = DiffGenerator.diff(\n    \"{\\\"name\\\": \\\"John\\\", \\\"timestamp\\\": \\\"2024-01-01\\\"}\",\n    \"{\\\"name\\\": \\\"John\\\", \\\"timestamp\\\": \\\"2024-12-31\\\"}\",\n    jsonMatcher\n);\n\nSystem.out.println(diff.similarityRate()); // 100.0\n```\n\n### Path Patterns\n\nThe `IgnoredPathMatcher` supports various path patterns:\n\n| Pattern | Description | Example |\n|---------|-------------|---------|\n| `name` | Matches field `name` at any level | Ignores `$.name`, `$.user.name`, `$.data.user.name` |\n| `user.name` | Matches `name` under `user` | Ignores `$.user.name`, `$.data.user.name` |\n| `*.name` | Wildcard for any property | Ignores `$.foo.name`, `$.bar.name` |\n| `items[0]` | Matches specific array index | Ignores `$.items[0]` |\n| `items[*]` | Wildcard for any array index | Ignores `$.items[0]`, `$.items[1]`, etc. |\n| `items[*].id` | Field in any array element | Ignores `$.items[0].id`, `$.items[5].id` |\n\n### Examples\n\n```java\n// Ignore a single field everywhere\nnew IgnoredPathMatcher(\"createdAt\")\n\n// Ignore multiple fields\nnew IgnoredPathMatcher(\"createdAt\", \"updatedAt\", \"id\")\n\n// Ignore nested field\nnew IgnoredPathMatcher(\"metadata.timestamp\")\n\n// Ignore field in all array elements\nnew IgnoredPathMatcher(\"users[*].password\")\n\n// Combine multiple patterns\nnew IgnoredPathMatcher(\"id\", \"*.createdAt\", \"items[*].internalId\")\n```\n\n**Important:**\n- Place `IgnoredPathMatcher` **before** other matchers in the constructor\n- Patterns match against the end of the path, so `name` matches `$.user.name` as well as `$.name`\n\n## Advanced Example\n\n```java\nfinal var expectedJson = \"\"\"\n    {\n        \"additionalProperty\": \"a\",\n        \"foo\": \"bar\",\n        \"bar\": \"bar\",\n        \"numberMatch\": 10.0,\n        \"numberUnmatched\": 10.01,\n        \"arrayMatch\": [{\"b\": \"a\"}],\n        \"arrayUnmatched\": [{\"b\": \"a\"}]\n    }\n    \"\"\";\n\nfinal var receivedJson = \"\"\"\n    {\n        \"foo\": \"foo\",\n        \"bar\": \"bar\",\n        \"numberMatch\": 10,\n        \"numberUnmatched\": 10.02,\n        \"arrayMatch\": [{\"b\": \"a\"}],\n        \"arrayUnmatched\": {\"b\": \"b\"}\n    }\n    \"\"\";\n\nfinal var jsonMatcher = new CompositeJsonMatcher(\n    new LenientJsonArrayPartialMatcher(),\n    new LenientJsonObjectPartialMatcher(),\n    new LenientNumberPrimitivePartialMatcher(),\n    new StrictPrimitivePartialMatcher()\n);\n\nfinal var diff = DiffGenerator.diff(expectedJson, receivedJson, jsonMatcher);\n\nSystem.out.println(OnlyErrorDiffViewer.from(diff));\nSystem.out.println(\"Similarity: \" + diff.similarityRate() + \"%\");\n```\n\nOutput:\n```\nThe property \"$.additionalProperty\" is not found\nThe property \"$.numberUnmatched\" didn't match. Expected 10.01, Received: 10.02\nThe property \"$.arrayUnmatched\" didn't match. Expected [{\"b\":\"a\"}], Received: {\"b\":\"b\"}\nThe property \"$.foo\" didn't match. Expected \"bar\", Received: \"foo\"\n\nSimilarity: 76.0%\n```\n\n## Creating Custom Matchers\n\nYou can create custom matchers by implementing the `PartialJsonMatcher\u003cT\u003e` interface:\n\n```java\npublic class MyCustomMatcher implements PartialJsonMatcher\u003cJsonNode\u003e {\n\n    @Override\n    public boolean manage(JsonNode expected, JsonNode received) {\n        // Return true if this matcher should handle this comparison\n        return /* your condition */;\n    }\n\n    @Override\n    public JsonDiff jsonDiff(Path path, JsonNode expected, JsonNode received, JsonMatcher jsonMatcher) {\n        // Return your diff result\n        if (/* values match */) {\n            return new MatchedPrimaryDiff(path, expected);\n        }\n        return new UnMatchedPrimaryDiff(path, expected, received);\n    }\n}\n```\n\n## License\n\nThis project is licensed under the MIT License.\n","funding_links":[],"categories":["\u003ca name=\"Java\"\u003e\u003c/a\u003eJava"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeblockt%2Fjson-diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeblockt%2Fjson-diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeblockt%2Fjson-diff/lists"}