{"id":13413899,"url":"https://github.com/kinbiko/jsonassert","last_synced_at":"2025-12-30T00:19:37.261Z","repository":{"id":34985983,"uuid":"154891082","full_name":"kinbiko/jsonassert","owner":"kinbiko","description":"A Go test assertion library for verifying that two representations of JSON are semantically equal","archived":false,"fork":false,"pushed_at":"2024-10-03T14:08:34.000Z","size":252,"stargazers_count":131,"open_issues_count":5,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-10T23:36:50.926Z","etag":null,"topics":["assertion-library","assertions","go","golang","hacktoberfest","json","json-payload","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","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/kinbiko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-26T20:31:01.000Z","updated_at":"2025-03-04T05:45:43.000Z","dependencies_parsed_at":"2024-06-18T14:43:27.554Z","dependency_job_id":null,"html_url":"https://github.com/kinbiko/jsonassert","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinbiko%2Fjsonassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinbiko%2Fjsonassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinbiko%2Fjsonassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinbiko%2Fjsonassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kinbiko","download_url":"https://codeload.github.com/kinbiko/jsonassert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243642007,"owners_count":20323948,"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":["assertion-library","assertions","go","golang","hacktoberfest","json","json-payload","testing"],"created_at":"2024-07-30T20:01:52.301Z","updated_at":"2025-12-30T00:19:37.222Z","avatar_url":"https://github.com/kinbiko.png","language":"Go","readme":"![logo](./logo.png)\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n[![Build Status](https://github.com/kinbiko/jsonassert/workflows/Go/badge.svg)](https://github.com/kinbiko/jsonassert/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/kinbiko/jsonassert)](https://goreportcard.com/report/github.com/kinbiko/jsonassert)\n[![Coverage Status](https://coveralls.io/repos/github/kinbiko/jsonassert/badge.svg)](https://coveralls.io/github/kinbiko/jsonassert)\n[![Latest version](https://img.shields.io/github/tag/kinbiko/jsonassert.svg?label=latest%20version\u0026style=flat)](https://github.com/kinbiko/jsonassert/releases)\n[![Go Documentation](http://img.shields.io/badge/godoc-documentation-blue.svg?style=flat)](https://pkg.go.dev/github.com/kinbiko/jsonassert)\n[![License](https://img.shields.io/github/license/kinbiko/jsonassert.svg?style=flat)](https://github.com/kinbiko/jsonassert/blob/master/LICENSE)\n\nIt's difficult to confirm that a JSON payload, e.g. a HTTP request or response body, does indeed look the way you want using the built-in Go testing package.\n`jsonassert` is an easy-to-use Go test assertion library for verifying that two representations of JSON are semantically equal.\n\n## Usage\n\nCreate a new `*jsonassert.Asserter` in your test and use this to make assertions against your JSON payloads:\n\n```go\nfunc TestWhatever(t *testing.T) {\n\tja := jsonassert.New(t)\n\t// find some sort of payload\n\tname := \"River Tam\"\n\tage := 16\n\tja.Assertf(payload, `\n\t{\n\t\t\"name\": \"%s\",\n\t\t\"age\": %d,\n\t\t\"averageTestScore\": \"%s\",\n\t\t\"skills\": [\n\t\t\t{ \"name\": \"martial arts\", \"level\": 99 },\n\t\t\t{ \"name\": \"intelligence\", \"level\": 100 },\n\t\t\t{ \"name\": \"mental fortitude\", \"level\": 4 }\n\t\t]\n\t}`, name, age, \"99%\")\n}\n```\n\nYou may pass in `fmt.Sprintf` arguments after the expected JSON structure.\nThis feature may be useful for the case when you already have variables in your test with the expected data or when your expected JSON contains a `%` character which could be misinterpreted as a format directive.\n\n`ja.Assertf()` supports assertions against **strings only**.\n\n### Check for presence only\n\nSome properties of a JSON payload may be difficult to know in advance.\nE.g. timestamps, UUIDs, or other randomly assigned values.\n\nFor these types of values, place the string `\"\u003c\u003cPRESENCE\u003e\u003e\"` as the expected value, and `jsonassert` will only verify that this key exists (i.e. the actual JSON has the expected key, and its value is not `null`), but this does not check its value.\n\nFor example:\n\n```go\nfunc TestWhatever(t *testing.T) {\n\tja := jsonassert.New(t)\n\tja.Assertf(`\n\t{\n\t\t\"time\": \"2019-01-28T21:19:42\",\n\t\t\"uuid\": \"94ae1a31-63b2-4a55-a478-47764b60c56b\"\n\t}`, `\n\t{\n\t\t\"time\": \"\u003c\u003cPRESENCE\u003e\u003e\",\n\t\t\"uuid\": \"\u003c\u003cPRESENCE\u003e\u003e\"\n\t}`)\n}\n```\n\nThe above will pass your test, but:\n\n```go\nfunc TestWhatever(t *testing.T) {\n\tja := jsonassert.New(t)\n\tja.Assertf(`\n\t{\n\t\t\"date\": \"2019-01-28T21:19:42\",\n\t\t\"uuid\": null\n\t}`, `\n\t{\n\t\t\"time\": \"\u003c\u003cPRESENCE\u003e\u003e\",\n\t\t\"uuid\": \"\u003c\u003cPRESENCE\u003e\u003e\"\n\t}`)\n}\n```\n\nThe above will fail your tests because the `time` key was not present in the actual JSON, and the `uuid` was `null`.\n\n### Ignore ordering in arrays\n\nIf your JSON payload contains an array with elements whose ordering is not deterministic, then you can use the `\"\u003c\u003cUNORDERED\u003e\u003e\"` directive as the first element of the array in question:\n\n```go\nfunc TestUnorderedArray(t *testing.T) {\n\tja := jsonassert.New(t)\n\tpayload := `[\"bar\", \"foo\", \"baz\"]`\n\tja.Assertf(payload, `[\"foo\", \"bar\", \"baz\"]`)                  // Order matters, will fail your test.\n\tja.Assertf(payload, `[\"\u003c\u003cUNORDERED\u003e\u003e\", \"foo\", \"bar\", \"baz\"]`) // Order agnostic, will pass your test.\n}\n```\n\n## Docs\n\nYou can find the [GoDocs for this package here](https://pkg.go.dev/github.com/kinbiko/jsonassert).\n\n## Contributing\n\nContributions are welcome. Please read the [contribution guidelines](./.github/CONTRIBUTING.md) and discuss feature requests in an issue before opening a PR.\n","funding_links":[],"categories":["Testing","测试","测试相关`测试库和测试数据集生成库`","Testing Frameworks","Repositories","测试相关","Template Engines"],"sub_categories":["Testing Frameworks","HTTP Clients","HTTP客户端","查询语"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinbiko%2Fjsonassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkinbiko%2Fjsonassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinbiko%2Fjsonassert/lists"}