{"id":36694281,"url":"https://github.com/araqnid/hamkrest-json","last_synced_at":"2026-01-12T11:26:31.986Z","repository":{"id":27439594,"uuid":"113926470","full_name":"araqnid/hamkrest-json","owner":"araqnid","description":"Hamkrest matchers for JSON","archived":false,"fork":false,"pushed_at":"2023-02-04T07:02:07.000Z","size":255,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-07-06T07:42:34.360Z","etag":null,"topics":["hamcrest","json","kotlin","matchers","testing"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/araqnid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-12T01:10:28.000Z","updated_at":"2022-11-09T20:06:45.000Z","dependencies_parsed_at":"2023-02-18T14:31:39.249Z","dependency_job_id":null,"html_url":"https://github.com/araqnid/hamkrest-json","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/araqnid/hamkrest-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/araqnid%2Fhamkrest-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/araqnid%2Fhamkrest-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/araqnid%2Fhamkrest-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/araqnid%2Fhamkrest-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/araqnid","download_url":"https://codeload.github.com/araqnid/hamkrest-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/araqnid%2Fhamkrest-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T10:58:46.209Z","status":"ssl_error","status_checked_at":"2026-01-12T10:58:42.742Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["hamcrest","json","kotlin","matchers","testing"],"created_at":"2026-01-12T11:26:31.769Z","updated_at":"2026-01-12T11:26:31.977Z","avatar_url":"https://github.com/araqnid.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON matchers for Hamkrest\n==========================\n\n[ ![Kotlin](https://img.shields.io/badge/kotlin-1.4.32-blue.svg)](http://kotlinlang.org)\n[![build](https://github.com/araqnid/hamkrest-json/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/araqnid/hamkrest-json/actions/workflows/gradle-build.yml)\n[![Maven Central](https://img.shields.io/maven-central/v/org.araqnid.hamkrest/hamkrest-json.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.araqnid.hamkrest%22%20AND%20a%3A%22hamkrest-json%22)\n\n[What is Hamkrest?](https://github.com/npryce/hamkrest)\n\nThese matchers are for matching JSON documents: they use Jackson to parse JSON bytes/text to an\nAST, and can match against that.\n\nEquivalence matchers\n--------------------\n\nMatch some text as JSON:\n\n```kotlin\n// matches despite spaces\nassertThat(\"\"\"{\"a\":1,\"b\":2}\"\"\", equivalentTo(\"\"\"{ \"a\" : 1, \"b\" : 2 }\"\"\"))\n```\n\n```kotlin\n// matches despite fields in other order\nassertThat(\"\"\"{\"b\":2,\"a\":1}\"\"\", equivalentTo(\"\"\"{ \"a\" : 1, \"b\" : 2 }\"\"\"))\n```\n\n```kotlin\n// pattern specified in matcher can be written more loosely\nassertThat(\"\"\"{\"a\":1,\"b\":\"foo\"}\"\"\", equivalentTo(\"\"\"{ a: 1, b: 'foo' }\"\"\"))\n```\n\nMatch a sequence of bytes:\n\n```kotlin\nassertThat(\"\"\"{\"a\":1,\"b\":2}\"\"\".toByteArray(), bytesEquivalentTo(\"\"\"{ \"a\" : 1, \"b\" : 2 }\"\"\"))\n```\n\nStructural matchers\n-------------------\n\nMatch AST nodes by specifying either the expected value or a matcher:\n\n```kotlin\nassertThat(\"\"\"42\"\"\", json(jsonInt(42)))\nassertThat(\"\"\"42\"\"\", json(jsonInt(equalTo(42))))\nassertThat(\"\"\"\"xyzzy\"\"\"\", json(jsonString(\"xyzzy\")))\nassertThat(\"\"\"\"xyzzy\"\"\"\", json(jsonString(anything)))\n```\n\n### Objects\n\nBuild matchers for objects:\n\n```kotlin\nassertThat(\"\"\"{ \"a\": 1, \"b\": 2 }\"\"\", json(jsonObject()\n  .withProperty(\"a\", 1)\n  .withProperty(\"b\", 2)\n))\n```\n\nBy default an object matcher will mismatch if the input contains additional properties, but\nthey can be allowed:\n\n```kotlin\nassertThat(\"\"\"{ \"a\": 1, \"b\": 2, \"foo\": \"bar\" }\"\"\", json(jsonObject()\n  .withProperty(\"a\", 1)\n  .withProperty(\"b\", 2)\n  .withAnyOtherProperties()\n))\n```\n\nIn general, `withProperty` accepts either values as the second argument (and infers a\nlikely node type) or a matcher of `JsonNode` (such as `jsonInt()` etc or another `jsonObject()`)\n\nShorthand for switching to an equivalence matcher:\n\n```kotlin\nassertThat(\"\"\"{ \"a\": { \"b\" : 1 } }\"\"\", json(jsonObject()\n  .withPropertyJSON(\"a\", \"\"\"{ b : 1}\"\"\")\n))\n```\n\n### Arrays\n\nBy default, `jsonArray()` will match only an empty array (change in future?)\n\nMatch contents exactly:\n\n```kotlin\nassertThat(\"\"\"[1, 2, 3]\"\"\", json(jsonArray().of(jsonInt(1), jsonInt(2), jsonInt(3))))\n```\n\nMatch any element:\n\n```kotlin\nassertThat(\"\"\"[1, 2, 3]\"\"\", json(jsonArray().including(jsonInt(2))))\n```\n\nMatch elements in any order:\n\n```kotlin\nassertThat(\"\"\"[1, 2, 3]\"\"\", json(jsonArray().inAnyOrder(jsonInt(2), jsonInt(1), jsonInt(3))))\n```\n\nGet the library\n---------------\n\nHamkrest-JSON is published on [Maven Central](https://search.maven.org). You need something like this in\n`build.gradle` or `build.gradle.kts`:\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\ndependencies {\n    testImplementation(\"org.araqnid.hamkrest:hamkrest-json:1.1.2\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faraqnid%2Fhamkrest-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faraqnid%2Fhamkrest-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faraqnid%2Fhamkrest-json/lists"}