{"id":13593329,"url":"https://github.com/skyscreamer/JSONassert","last_synced_at":"2025-04-09T02:33:20.981Z","repository":{"id":2365390,"uuid":"3329435","full_name":"skyscreamer/JSONassert","owner":"skyscreamer","description":"Write JSON unit tests in less code. Great for testing REST interfaces.","archived":false,"fork":false,"pushed_at":"2024-07-28T18:03:56.000Z","size":1366,"stargazers_count":1028,"open_issues_count":88,"forks_count":202,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-03-31T13:55:38.560Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://jsonassert.skyscreamer.org","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/skyscreamer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2012-02-01T21:55:17.000Z","updated_at":"2025-03-15T11:52:08.000Z","dependencies_parsed_at":"2024-01-03T05:43:49.454Z","dependency_job_id":"83084d51-8970-41c3-ab44-53c28a9803c1","html_url":"https://github.com/skyscreamer/JSONassert","commit_stats":{"total_commits":198,"total_committers":32,"mean_commits":6.1875,"dds":0.696969696969697,"last_synced_commit":"e81c16c59ce0860f97a65d871589ab2337370c4b"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyscreamer%2FJSONassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyscreamer%2FJSONassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyscreamer%2FJSONassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyscreamer%2FJSONassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyscreamer","download_url":"https://codeload.github.com/skyscreamer/JSONassert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247965845,"owners_count":21025447,"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":[],"created_at":"2024-08-01T16:01:19.256Z","updated_at":"2025-04-09T02:33:19.627Z","avatar_url":"https://github.com/skyscreamer.png","language":"Java","readme":"JSONassert\n==========\n\nWrite JSON unit tests in less code.  Great for testing REST interfaces.\n\nSummary\n-------\n\nWrite JSON tests as if you are comparing a string.  Under the covers, JSONassert converts your string into a JSON object and compares the logical structure and data with the actual JSON.  When _strict_ is set to false (recommended), it forgives reordering data and extending results (as long as all the expected elements are there), making tests less brittle.\n\nSupported test frameworks:\n\n * [JUnit](http://junit.org)\n\nExamples\n--------\n\nIn JSONassert you write and maintain something like this:\n\n    JSONObject data = getRESTData(\"/friends/367.json\");\n    String expected = \"{friends:[{id:123,name:\\\"Corby Page\\\"},{id:456,name:\\\"Carter Page\\\"}]}\";\n    JSONAssert.assertEquals(expected, data, false);\n\ninstead of all this:\n\n\u003cpre\u003e\u003ccode\u003e\u003cdel\u003e\nJSONObject data = getRESTData(\"/friends/367.json\");\nAssert.assertTrue(data.has(\"friends\"));\nObject friendsObject = data.get(\"friends\");\nAssert.assertTrue(friendsObject instanceof JSONArray);\nJSONArray friends = (JSONArray) friendsObject;\nAssert.assertEquals(2, friends.length());\nJSONObject friend1Obj = friends.getJSONObject(0);\nAssert.assertTrue(friend1Obj.has(\"id\"));\nAssert.assertTrue(friend1Obj.has(\"name\"));\nJSONObject friend2Obj = friends.getJSONObject(1);\nAssert.assertTrue(friend2Obj.has(\"id\"));\nAssert.assertTrue(friend2Obj.has(\"name\"));\n\nif (\"Carter Page\".equals(friend1Obj.getString(\"name\"))) {\n    Assert.assertEquals(456, friend1Obj.getInt(\"id\"));\n    Assert.assertEquals(\"Corby Page\", friend2Obj.getString(\"name\"));\n    Assert.assertEquals(123, friend2Obj.getInt(\"id\"));\n}\nelse if (\"Corby Page\".equals(friend1Obj.getString(\"name\"))) {\n    Assert.assertEquals(123, friend1Obj.getInt(\"id\"));\n    Assert.assertEquals(\"Carter Page\", friend2Obj.getString(\"name\"));\n    Assert.assertEquals(456, friend2Obj.getInt(\"id\"));\n}\nelse {\n    Assert.fail(\"Expected either Carter or Corby, Got: \" + friend1Obj.getString(\"name\"));\n}\n\u003c/del\u003e\u003c/code\u003e\u003c/pre\u003e\n\nError Messages\n--------------\n\nWe tried to make error messages easy to understand.  This is really important, since it gets hard for the eye to pick out the difference, particularly in long JSON strings.  For example:\n\n    String expected = \"{id:1,name:\\\"Joe\\\",friends:[{id:2,name:\\\"Pat\\\",pets:[\\\"dog\\\"]},{id:3,name:\\\"Sue\\\",pets:[\\\"bird\\\",\\\"fish\\\"]}],pets:[]}\";\n    String actual = \"{id:1,name:\\\"Joe\\\",friends:[{id:2,name:\\\"Pat\\\",pets:[\\\"dog\\\"]},{id:3,name:\\\"Sue\\\",pets:[\\\"cat\\\",\\\"fish\\\"]}],pets:[]}\"\n    JSONAssert.assertEquals(expected, actual, false);\n\nreturns the following:\n\n    friends[id=3].pets[]: Expected bird, but not found ; friends[id=3].pets[]: Contains cat, but not expected\n\nWhich tells you that the pets array under the friend where id=3 was supposed to contain \"bird\", but had \"cat\" instead.  (Maybe the cat ate the bird?)\n\n* * *\n\nQuickStart\n----------\n\nTo use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) or add the following to your project's pom.xml:\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.skyscreamer\u003c/groupId\u003e\n        \u003cartifactId\u003ejsonassert\u003c/artifactId\u003e\n        \u003cversion\u003e2.0-rc1\u003c/version\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n\nWrite tests like this:\n\n\u003ccode\u003eJSONAssert.assertEquals(\u003ci\u003eexpectedJSONString\u003c/i\u003e, \u003ci\u003eactualJSON\u003c/i\u003e, \u003ci\u003estrictMode\u003c/i\u003e);\u003c/code\u003e\n\n[More examples in our cookbook](http://jsonassert.skyscreamer.org/cookbook.html)\n\n* * *\n\nWho uses JSONassert?\n--------------------\n + [yoga](https://github.com/skyscreamer/yoga) - A relational REST framework\n + [hamcrest-json](https://github.com/hertzsprung/hamcrest-json) - Hamcrest matchers for comparing JSON documents\n + [Mule ESB](http://www.mulesoft.org/)\n + [GroupDocs](http://groupdocs.com/)\n + [Shazam](http://www.shazam.com/)\n + [Thucydides](http://thucydides.net/)\n + [and over a thousand more](https://mvnrepository.com/artifact/org.skyscreamer/jsonassert)...\n\n* * *\n\norg.json\n--------\n\nAs of v2, JSONAssert uses @stleary's [JSON-java](https://github.com/stleary/JSON-java) implementation of org.json, the\nmost commonly used reference implementation for JSON in Java.\n\nResources\n---------\n\n[JavaDoc](http://jsonassert.skyscreamer.org/apidocs/index.html)\n\n","funding_links":[],"categories":["Java","Testing","测试"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyscreamer%2FJSONassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyscreamer%2FJSONassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyscreamer%2FJSONassert/lists"}