{"id":24919746,"url":"https://github.com/steinfletcher/apitest-jsonpath","last_synced_at":"2025-06-14T12:05:42.723Z","repository":{"id":51655256,"uuid":"164497766","full_name":"steinfletcher/apitest-jsonpath","owner":"steinfletcher","description":"JSONPath assertions for apitest","archived":false,"fork":false,"pushed_at":"2023-09-28T16:04:24.000Z","size":50,"stargazers_count":24,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-14T12:05:15.410Z","etag":null,"topics":["apitest","behavioural-tests","go","golang","jsonpath","testing"],"latest_commit_sha":null,"homepage":"https://apitest.dev","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/steinfletcher.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}},"created_at":"2019-01-07T21:20:38.000Z","updated_at":"2025-06-04T09:28:27.000Z","dependencies_parsed_at":"2024-06-18T18:16:38.236Z","dependency_job_id":null,"html_url":"https://github.com/steinfletcher/apitest-jsonpath","commit_stats":null,"previous_names":["steinfletcher/api-test-jsonpath"],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/steinfletcher/apitest-jsonpath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-jsonpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-jsonpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-jsonpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-jsonpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steinfletcher","download_url":"https://codeload.github.com/steinfletcher/apitest-jsonpath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-jsonpath/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259813010,"owners_count":22915198,"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":["apitest","behavioural-tests","go","golang","jsonpath","testing"],"created_at":"2025-02-02T10:37:21.344Z","updated_at":"2025-06-14T12:05:42.699Z","avatar_url":"https://github.com/steinfletcher.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Test](https://github.com/steinfletcher/apitest-jsonpath/workflows/Test/badge.svg)\n\n# apitest-jsonpath\n\nThis library provides jsonpath assertions for [apitest](https://github.com/steinfletcher/apitest).\n\n# Installation\n\n```bash\ngo get -u github.com/steinfletcher/apitest-jsonpath\n```\n\n## Examples\n\n### Equal\n\n`Equal` checks for value equality when the json path expression returns a single result. Given the response is `{\"id\": 12345}`\n\n```go\napitest.New(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.Equal(`$.id`, float64(12345))).\n\tEnd()\n```\n\nWe can also provide more complex expected values. Given the response `{\"message\": \"hello\", \"id\": 12345}`.\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.Equal(`$`, map[string]interface{}{\"message\": \"hello\", \"id\": float64(12345)})).\n\tEnd()\n```\n\n### NotEqual\n\n`NotEqual` checks that the json path expression value is not equal to given value\n\n```go\napitest.New(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.NotEqual(`$.a`, float64(56789))).\n\tEnd()\n```\n\nwe can also provide more complex expected values\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.NotEqual(`$`, map[string]interface{}{\"a\": \"hello\", \"b\": float64(56789)})).\n\tEnd()\n```\n\ngiven the response is `{\"a\": \"hello\", \"b\": 12345}`\n\n### Contains\n\nWhen the jsonpath expression returns an array, use `Contains` to assert that the expected value is contained in the result. Given the response is `{\"a\": 12345, \"b\": [{\"key\": \"c\", \"value\": \"result\"}]}`, we can assert on the result like so\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.Contains(`$.b[? @.key==\"c\"].value`, \"result\")).\n\tEnd()\n```\n\n### Present / NotPresent\n\nUse `Present` and `NotPresent` to check the presence of a field in the response without evaluating its value.\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.Present(`$.a`)).\n\tAssert(jsonpath.NotPresent(`$.password`)).\n\tEnd()\n```\n\n### Matches\n\nUse `Matches` to check that a single path element of type string, number or bool matches a regular expression.\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/hello\").\n\tExpect(t).\n\tAssert(jsonpath.Matches(`$.a`, `^[abc]{1,3}$`)).\n\tEnd()\n```\n\n### Len\n\nUse `Len` to check to the length of the returned value. Given the response is `{\"items\": [1, 2, 3]}`, we can assert on the length of items like so\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/articles?category=golang\").\n\tExpect(t).\n\tAssert(jsonpath.Len(`$.items`, 3)).\n\tEnd()\n```\n\n### GreaterThan\n\nUse `GreaterThan` to enforce a minimum length on the returned value.\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/articles?category=golang\").\n\tExpect(t).\n\tAssert(jsonpath.GreaterThan(`$.items`, 2)).\n\tEnd()\n```\n\n### LessThan\n\nUse `LessThan` to enforce a maximum length on the returned value.\n\n```go\napitest.New().\n\tHandler(handler).\n\tGet(\"/articles?category=golang\").\n\tExpect(t).\n\tAssert(jsonpath.LessThan(`$.items`, 4)).\n\tEnd()\n```\n\n### JWT matchers\n\n`JWTHeaderEqual` and `JWTPayloadEqual` can be used to assert on the contents of the JWT in the response (it does not verify a JWT).\n\n```go\nfunc TestX(t *testing.T) {\n\tapitest.New().\n\t\tHandlerFunc(myHandler).\n\t\tPost(\"/login\").\n\t\tExpect(t).\n\t\tAssert(jsonpath.JWTPayloadEqual(fromAuthHeader, `$.sub`, \"1234567890\")).\n\t\tAssert(jsonpath.JWTHeaderEqual(fromAuthHeader, `$.alg`, \"HS256\")).\n\t\tEnd()\n}\n\nfunc fromAuthHeader(res *http.Response) (string, error) {\n\treturn res.Header.Get(\"Authorization\"), nil\n}\n```\n\n### Chain\n\n`Chain` is used to provide several assertions at once\n\n```go\nAssert(\n\tjsonpath.Chain().\n\t\tEqual(\"a\", \"1\").\n\t\tNotEqual(\"b\", \"2\").\n\t\tPresent(\"c\").\n\t\tEnd(),\n).\n```\n\n### Root\n\n`Root` is used to avoid duplicated paths in body expectations. For example, instead of writing:\n\n```go\nAssert(jsonpath.Equal(\"a.b.c.d\", \"a\").\nAssert(jsonpath.Equal(\"a.b.c.e\", \"b\").\nAssert(jsonpath.Equal(\"a.b.c.f\", \"c\").\n```\n\nit is possible to define a root path like so\n\n```go\nAssert(\n\tjsonpath.Root(\"$.a.b.c\").\n\t\tEqual(\"d\", \"a\").\n\t\tEqual(\"e\", \"b\").\n\t\tEqual(\"f\", \"c\").\n\t\tEnd(),\n).\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteinfletcher%2Fapitest-jsonpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteinfletcher%2Fapitest-jsonpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteinfletcher%2Fapitest-jsonpath/lists"}