{"id":13769064,"url":"https://github.com/duailibe/jest-json","last_synced_at":"2026-01-18T11:01:31.466Z","repository":{"id":37942426,"uuid":"141628410","full_name":"duailibe/jest-json","owner":"duailibe","description":"Jest matchers to work with JSON strings","archived":false,"fork":false,"pushed_at":"2025-09-09T15:21:48.000Z","size":72,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-13T11:56:38.305Z","etag":null,"topics":["hacktoberfest","javascript","jest","jest-matchers","json","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/duailibe.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}},"created_at":"2018-07-19T20:37:20.000Z","updated_at":"2025-09-09T15:21:51.000Z","dependencies_parsed_at":"2024-01-12T09:45:39.946Z","dependency_job_id":null,"html_url":"https://github.com/duailibe/jest-json","commit_stats":{"total_commits":48,"total_committers":3,"mean_commits":16.0,"dds":0.125,"last_synced_commit":"b6f79c77a0019212d3601e0b503bea43b5c3f317"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/duailibe/jest-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duailibe%2Fjest-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duailibe%2Fjest-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duailibe%2Fjest-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duailibe%2Fjest-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duailibe","download_url":"https://codeload.github.com/duailibe/jest-json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duailibe%2Fjest-json/sbom","scorecard":{"id":358749,"data":{"date":"2025-08-11","repo":{"name":"github.com/duailibe/jest-json","commit":"b6f79c77a0019212d3601e0b503bea43b5c3f317"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/29 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":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"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":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/duailibe/jest-json/ci.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/duailibe/jest-json/ci.yaml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yaml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/duailibe/jest-json/ci.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/duailibe/jest-json/ci.yaml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yaml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/duailibe/jest-json/ci.yaml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yaml:1","Info: no jobLevel write permissions found"],"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":"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":"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":"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":"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":"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":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: 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 'main'"],"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 7 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-18T10:15:28.319Z","repository_id":37942426,"created_at":"2025-08-18T10:15:28.319Z","updated_at":"2025-08-18T10:15:28.319Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28535156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["hacktoberfest","javascript","jest","jest-matchers","json","testing"],"created_at":"2024-08-03T17:00:16.557Z","updated_at":"2026-01-18T11:01:31.451Z","avatar_url":"https://github.com/duailibe.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Matchers"],"readme":"# `jest-json`\n\n[![npm](https://img.shields.io/npm/v/jest-json.svg)](https://npmjs.org/jest-json)\n[![CI](https://github.com/duailibe/jest-json/actions/workflows/ci.yaml/badge.svg)](https://github.com/duailibe/jest-json/actions/workflows/ci.yaml)\n\nJest matchers to work with JSON strings.\n\n## Setup\n\n**Note:** If you're using Jest \u003c 27.2.5, you should stick to `jest-json@^1.0`.\n\nAdd `jest-json` to your Jest config:\n\n```json\n{\n  \"setupTestFrameworkScriptFile\": \"jest-json\"\n}\n```\n\nOr if you're already using another test framework, create a setup file and require each of them:\n\n```js\nrequire(\"jest-json\");\n// require(\"some-jest-library);\n```\n\n## Motivation\n\nSay you have a function `fetchData` the calls `fetch` with a JSON body and you want to assert that `fetchData` is building the JSON string correctly.\n\n_See this [repl.it](https://repl.it/@duailibe/jest-json-example) for a working example of this problem._\n\n```js\nfunction fetchData(userId, fields = []) {\n  if (!fields.includes(\"profilePicture\")) {\n    fields = fields.concat([\"profilePicture\"]);\n  }\n\n  return fetch(\"/users\", {\n    method: \"POST\",\n    headers: { \"Content-Type\": \"application/json\" },\n    body: JSON.stringify({\n      params: { id: userId },\n      fields,\n    }),\n  });\n}\n```\n\nOne option to write the test would be to check the final string:\n\n```js\ntest(\"fetchData\", () =\u003e {\n  fetchData(\"ab394js\", [\"name\", \"website\"]);\n\n  expect(fetch).toHaveBeenCalledWith(\"/users\", {\n    method: \"POST\",\n    headers: expect.anything(),\n    body: JSON.stringify({\n      params: { id: \"ab394js\" },\n      fields: [\"name\", \"website\", \"profilePicture\"],\n    }),\n  });\n});\n```\n\nOk, this works, but that has a few problems:\n\n- you are testing that `\"profilePicture\"` will be added to the end of the `fields` list,\n- you are testing the exact orders the keys of the body JSON are added.\n\nIf someone changes the test to insert `\"profilePicture\"` in the beginning of the list, or change the JSON to `JSON.stringify({ fields, params })`, your test will now fail because the JSON string changed, even though it's equivalent to the one in the test. That means we have a flaky test. One way to fix it would be:\n\n```js\nglobal.fetch = jest.fn();\n\ntest(\"fetchData\", () =\u003e {\n  fetchData(\"ab394js\", [\"name\", \"website\"]);\n\n  expect(fetch).toHaveBeenCalledWith(\"/users\", {\n    method: \"POST\",\n    headers: expect.anything(),\n    body: expect.anything(),\n  });\n\n  expect(JSON.parse(fetch.mock.calls[0][1].body)).toEqual({\n    params: { id: \"ab394js\" },\n    fields: expect.arrayContaining([\"name\", \"website\", \"profilePicture\"]),\n  });\n});\n```\n\nThat's better, and now we can even use `expect.arrayContaining()` to make sure we assert that the values are present, but don't care about the order.\n\nBut that's a really inconvenient way to get the string we're interested (`fetch.mock.calls[0][1].body`).\n\nNow compare that test to this:\n\n```js\nglobal.fetch = jest.fn();\n\ntest(\"fetchData\", () =\u003e {\n  fetchData(\"ab394js\", [\"name\", \"website\"]);\n\n  expect(fetch).toHaveBeenCalledWith(\"/users\", {\n    method: \"POST\",\n    headers: expect.anything(),\n    body: expect.jsonMatching({\n      params: { id: \"ab394js\" },\n      fields: expect.arrayContaining([\"name\", \"website\", \"profilePicture\"]),\n    }),\n  });\n});\n```\n\nNow that's a very neat test.\n\n## API\n\n### `expect.jsonMatching`\n\nIn the example above, you can use the `expect.jsonMatching` asymmetric matcher:\n\n```js\nexpect(foo).toHaveBeenCalledWith(\n  \"url\",\n  expect.jsonMatching({\n    foo: \"bar\",\n    spam: \"eggs\",\n  })\n);\n```\n\nYou can include other asymmetric matchers inside like:\n\n\u003c!-- prettier-ignore --\u003e\n```js\nexpect.jsonMatching(\n  expect.objectContaining({\n    foo: expect.stringMatching(\"bar\")\n  })\n)\n```\n\n### `expect().toMatchJSON()`\n\nIt's just sugar for calling `JSON.parse()` and then `expect().toEqual()`:\n\n```js\nexpect(json).toMatchJSON(expected);\n// equivalent to:\nconst tmp = JSON.parse(json);\nexpect(tmp).toEqual(expected);\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduailibe%2Fjest-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduailibe%2Fjest-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduailibe%2Fjest-json/lists"}