{"id":127342,"date":"2024-11-06T16:16:51","date_gmt":"2024-11-06T14:16:51","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=127342"},"modified":"2024-11-06T16:16:55","modified_gmt":"2024-11-06T14:16:55","slug":"asserting-json-responses-with-rest-assured-in-java","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html","title":{"rendered":"Asserting JSON Responses with REST-Assured in Java"},"content":{"rendered":"<p>This article explores how to use Java REST-assured to efficiently assert JSON responses in REST API testing. REST-assured is a Java library specifically designed for testing REST APIs, allowing developers to make HTTP calls and verify responses with ease. When working with APIs, verifying JSON response structures and values is essential to ensure data accuracy and consistency across applications. The article will also focus on asserting properties within arrays in JSON responses.<\/p>\n<h2 class=\"wp-block-heading\">1. Sample JSON Structure<\/h2>\n<p>To understand how we can assert JSON responses effectively, let\u2019s start with an overview of a sample JSON structure that represents a typical API response. This structure will serve as the basis for illustrating different assertion techniques using Java REST-assured.<\/p>\n<p>Consider the following JSON response from an API endpoint that provides user session information:<\/p>\n<pre class=\"brush:javascript,json\">\n{\n  \"activeSession\": true,\n  \"token\": \"abc123\",\n  \"details\": [\n    {\n      \"accountType\": 2,\n      \"accountDescription\": \"Premium\",\n      \"username\": \"mr_fish\",\n      \"clientId\": 42\n    }\n  ]\n}\n\n<\/pre>\n<p>This JSON has an array field <code>details<\/code>, and our goal is to verify the values of the properties within that array.<\/p>\n<p>Here is a controller class, <code>SessionInfoController<\/code>, to handle the HTTP request and produce the above JSON response.<\/p>\n<pre class=\"brush:java\">\n@RestController\n@RequestMapping(\"\/api\")\npublic class SessionInfoController {\n\n    @GetMapping(\"\/session-info\")\n    public Map&lt;String, Object&gt; getSessionInfo() {\n\n        Map&lt;String, Object&gt; sessionInfo = Map.of(\n                \"activeSession\", true,\n                \"token\", \"abc123\",\n                \"details\", Collections.singletonList(\n                        Map.of(\n                                \"accountType\", 2,\n                                \"accountDescription\", \"Premium\",\n                                \"username\", \"mr_fish\",\n                                \"clientId\", 42\n                        )\n                )\n        );\n\n        return sessionInfo;\n    }\n}\n<\/pre>\n<h2 class=\"wp-block-heading\">2. Setting Up REST-assured<\/h2>\n<p>To begin, it\u2019s essential to have REST-assured configured in the project. Adding REST-assured to the project dependencies will enable testing of JSON responses. For configuration with Maven, include the following dependency in the <code>pom.xml<\/code> file:<\/p>\n<pre class=\"brush:xml\">\n        &lt;dependency&gt;\n            &lt;groupId&gt;io.rest-assured&lt;\/groupId&gt;\n            &lt;artifactId&gt;rest-assured&lt;\/artifactId&gt;\n            &lt;version&gt;5.4.0&lt;\/version&gt;\n            &lt;scope&gt;test&lt;\/scope&gt;\n        &lt;\/dependency&gt;\n<\/pre>\n<h2 class=\"wp-block-heading\">3. Example Test: Asserting Array Properties<\/h2>\n<p>Consider an endpoint <code>\/session-info<\/code> that returns this JSON data. The test will be structured to validate each property\u2019s values precisely. Begin by setting REST-assured\u2019s base URI to point to the API server. Then, write the test case using REST-assured\u2019s <code>given()<\/code>, <code>when()<\/code>, and <code>then()<\/code> methods to define assertions for each JSON field, ensuring the response data aligns with expected values. <\/p>\n<p>The <code>body()<\/code> method in REST-assured is essential for checking specific fields in a JSON response. Used with <code>equalTo()<\/code>, it verifies that each field has the correct value, ensuring the data is accurate and consistent.<\/p>\n<pre class=\"brush:java\">\npublic class SessionInfoTest {\n\n    @BeforeAll\n    public static void setup() {\n        RestAssured.baseURI = \"http:\/\/localhost:8080\/api\";\n    }\n\n    @Test\n    public void testSessionInfoResponse() {\n        given()\n                .contentType(ContentType.JSON)\n                .when()\n                .get(\"\/session-info\")\n                .then()\n                .statusCode(200)\n                .body(\"activeSession\", equalTo(true))\n                .body(\"token\", equalTo(\"abc123\"))\n                .body(\"details\", hasSize(1))\n                .body(\"details[0].accountType\", equalTo(2))\n                .body(\"details[0].accountDescription\", equalTo(\"Premium\"))\n                .body(\"details[0].username\", equalTo(\"mr_fish\"))\n                .body(\"details[0].clientId\", equalTo(42));\n    }\n}\n<\/pre>\n<p>Here\u2019s an explanation of each assertion.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul class=\"wp-block-list\">\n<li><code>body(\"activeSession\", equalTo(true))<\/code>: Asserts that the <code>activeSession<\/code> property is <code>true<\/code>.<\/li>\n<li><code>body(\"token\", equalTo(\"abc123\"))<\/code>: Verifies that the <code>token<\/code> field matches the expected string <code>\"abc123\"<\/code>.<\/li>\n<li><code>body(\"details\", hasSize(1))<\/code>: Checks that the <code>details<\/code> array has exactly one object.<\/li>\n<li><code>body(\"details[0].accountType\", equalTo(2))<\/code>: Asserts that the <code>accountType<\/code> field in the first element of <code>details<\/code> is <code>2<\/code>.<\/li>\n<li><code>body(\"details[0].accountDescription\", equalTo(\"Premium\"))<\/code>: Verifies the <code>accountDescription<\/code> field is <code>\"Premium\"<\/code>.<\/li>\n<li><code>body(\"details[0].username\", equalTo(\"mr_fish\"))<\/code>: Checks the <code>username<\/code> field is <code>\"mr_fish\"<\/code>.<\/li>\n<li><code>body(\"details[0].clientId\", equalTo(42))<\/code>: Asserts that the <code>clientId<\/code> field in the first element of <code>details<\/code> is <code>42<\/code>.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.1 Asserting the Entire JSON Body as a String<\/h3>\n<p>REST-assured provides the <code>.extract()<\/code> method, which allows us to capture the response after performing assertions. This approach is useful for checking the full structure and content of the response in one assertion. <\/p>\n<pre class=\"brush:java\">\n    @Test\n    public void testWholeJsonBody() {\n        \/\/ Extract the JSON response body as a string\n        String body = given()\n                .get(\"\/session-info\")\n                .then()\n                .extract()\n                .body()\n                .asString();\n\n        \/\/ Assert the entire JSON structure as a single string\n        assertThat(body)\n                .isEqualTo(\"{\\\"details\\\":[{\\\"accountDescription\\\":\\\"Premium\\\",\\\"clientId\\\":42,\\\"username\\\":\\\"mr_fish\\\",\\\"accountType\\\":2}],\\\"activeSession\\\":true,\\\"token\\\":\\\"abc123\\\"}\");\n    }\n}\n\n<\/pre>\n<ul class=\"wp-block-list\">\n<li><strong>Extracting JSON as String<\/strong>: The <code>given().get(\"\/session-info\").then().extract().body().asString()<\/code> retrieves the JSON response body from the <code>\/session-info<\/code> endpoint as a single string.<\/li>\n<li><strong>Asserting the JSON String<\/strong>: Using <code>assertThat(body).isEqualTo(...)<\/code>, we directly compare the extracted JSON string to the expected JSON string to ensure that the entire response body matches exactly.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">4. Asserting With JSONAssert<\/h2>\n<p>Comparing JSON as plain strings can lead to test failures due to field ordering differences. We might encounter errors which indicate that the actual JSON response has fields in a different order than expected. JSON objects do not enforce a specific order for fields, so this discrepancy can occur without affecting the content&#8217;s meaning.<\/p>\n<p>To handle this, we can use <strong>JSONAssert<\/strong> to perform a relaxed comparison that ignores the order of fields. Here\u2019s how to modify the test to use <strong>JSONAssert<\/strong> for an order-independent assertion. <\/p>\n<pre class=\"brush:java\">\n    @Test\n    void whenGetBody_thenCanCompareByWholeString() throws Exception {\n        \/\/ Extract the JSON response body as a string\n        String body = given()\n            .get(\"\/session-info\")\n            .then()\n            .extract()\n            .body()\n            .asString();\n\n        \/\/ Expected JSON string\n        String expectedJson = \"{\\\"activeSession\\\":true,\\\"token\\\":\\\"abc123\\\",\\\"details\\\":[{\\\"accountType\\\":2,\\\"accountDescription\\\":\\\"Premium\\\",\\\"username\\\":\\\"mr_fish\\\",\\\"clientId\\\":42}]}\";\n\n        \/\/ Assert JSON, ignoring field order\n        JSONAssert.assertEquals(expectedJson, body, JSONCompareMode.LENIENT);\n    }\n<\/pre>\n<ul class=\"wp-block-list\">\n<li><code>JSONAssert.assertEquals()<\/code>: This method allows for JSON comparisons that are tolerant of field order, preventing test failures due to differences in JSON key ordering.<\/li>\n<li><code>JSONCompareMode.LENIENT<\/code>: This mode ignores field order, comparing only the structure and values within the JSON data. This approach ensures that tests pass as long as all required fields and values are present, regardless of their order.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">5. Asserting JSON with JSON Assert Hamcrest and JSON Unit Hamcrest<\/h2>\n<p>When dealing with JSON responses that contain dynamic or changeable fields, <strong>JSON Assert Hamcrest<\/strong> and <strong>JSONUnit Hamcrest<\/strong> provide effective ways to handle these variances while allowing the test to focus on expected fields and values. Both libraries can be used in combination with REST-assured for flexible assertions that ignore extra fields.<\/p>\n<p><strong>Adding Dependencies for JSON Assert Hamcrest and JSONUnit Hamcrest<\/strong><\/p>\n<p>To use JSON Assert Hamcrest and JSON Unit Hamcrest, the following dependencies should be added to the <code>pom.xml<\/code>:<\/p>\n<pre class=\"brush:xml\">\n&lt;dependency&gt;\n    &lt;groupId&gt;uk.co.datumedge&lt;\/groupId&gt;\n    &lt;artifactId&gt;hamcrest-json&lt;\/artifactId&gt;\n    &lt;version&gt;0.2&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n    &lt;groupId&gt;net.javacrumbs.json-unit&lt;\/groupId&gt;\n    &lt;artifactId&gt;json-unit&lt;\/artifactId&gt;\n    &lt;version&gt;2.27.0&lt;\/version&gt;\n    &lt;scope&gt;test&lt;\/scope&gt;\n&lt;\/dependency&gt;\n\n<\/pre>\n<h3 class=\"wp-block-heading\">5.1 Using JSON Assert Hamcrest<\/h3>\n<p>With <strong><a href=\"https:\/\/www.javacodegeeks.com\/2018\/03\/junit-hamcrest-matcher-for-json.html\" target=\"_blank\" rel=\"noreferrer noopener\">JSON Assert Hamcrest<\/a><\/strong>, we can load an expected JSON structure from a file and assert it against the response while allowing extra fields in the JSON. Assuming we have an <code>expected.json<\/code> file containing the expected JSON structure in the <code>src\/test\/resources<\/code> directory. Here\u2019s how to write a test using JSON Assert Hamcrest:<\/p>\n<pre class=\"brush:java\">\n    @Test\n    void assertJsonWithExtraFields_JsonAssert() {\n        given()\n                .get(\"\/session-info\")\n                .then()\n                .body(sameJSONAs(Files.contentOf(new File(\"src\/test\/resources\/expected.json\"), StandardCharsets.UTF_8))\n                        .allowingExtraUnexpectedFields());\n    }\n<\/pre>\n<p>In this example:<\/p>\n<ul class=\"wp-block-list\">\n<li><code>sameJSONAs<\/code>: Loads the expected JSON structure from <code>expected.json<\/code> and compares it to the actual JSON response.<\/li>\n<li><code>allowingExtraUnexpectedFields()<\/code>: Ignores any additional fields in the actual JSON response, focusing on matching fields in the expected JSON.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">5.2 Using JSONUnit Hamcrest<\/h3>\n<p>With <a href=\"https:\/\/github.com\/lukas-krecan\/JsonUnit\" target=\"_blank\" rel=\"noreferrer noopener\">JSONUnit<\/a> Hamcrest, we can use options to make comparisons more flexible, such as ignoring extra fields or handling nested fields.<\/p>\n<pre class=\"brush:java\">\n    @Test\n    void compareFieldsWithJsonUnitIgnoringExtras() {\n        given()\n            .get(\"\/session-info\")\n            .then()\n            .body(jsonEquals(Files.contentOf(new File(\"src\/test\/resources\/expected.json\"), StandardCharsets.UTF_8))\n            .when(Option.IGNORING_EXTRA_FIELDS));\n    }\n<\/pre>\n<p>In this example:<\/p>\n<ul class=\"wp-block-list\">\n<li><code>jsonEquals<\/code>: Compares the actual JSON response to the expected JSON structure loaded from the file.<\/li>\n<li><code>Option.IGNORING_EXTRA_FIELDS<\/code>: Ignores any additional fields not specified in <code>expected.json<\/code>, ensuring only relevant fields are validated.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n<p>In this article, the use of REST-assured for asserting JSON responses in Java has been explored, demonstrating several techniques for validating JSON structures effectively. By using REST-assured\u2019s <code>body()<\/code> and <code>equalTo()<\/code> methods, along with additional tools like JSON Assert Hamcrest and JSON Unit Hamcrest, testers can achieve precise, flexible assertions that handle complex scenarios, including ignoring extra fields or comparing entire JSON bodies as strings.<\/p>\n<h2 class=\"wp-block-heading\">7. Download the Source Code<\/h2>\n<p>This article focused on using Java REST-assured to assert JSON responses.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-test.zip\"><strong>java rest assured assert json responses<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This article explores how to use Java REST-assured to efficiently assert JSON responses in REST API testing. REST-assured is a Java library specifically designed for testing REST APIs, allowing developers to make HTTP calls and verify responses with ease. When working with APIs, verifying JSON response structures and values is essential to ensure data accuracy &hellip;<\/p>\n","protected":false},"author":128888,"featured_media":128246,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[3165,3167,3168,3166],"class_list":["post-127342","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-json-assertion","tag-json-hamcrest","tag-jsonunit","tag-rest-assured"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Asserting JSON Responses with REST-Assured in Java - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Asserting JSON Responses with REST-Assured in Java - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/web.facebook.com\/omos.aziegbe\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-06T14:16:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-06T14:16:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Omozegie Aziegbe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/OAziegbe\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Omozegie Aziegbe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html\"},\"author\":{\"name\":\"Omozegie Aziegbe\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d3eac6e45542536e961129ae0fb453e\"},\"headline\":\"Asserting JSON Responses with REST-Assured in Java\",\"datePublished\":\"2024-11-06T14:16:51+00:00\",\"dateModified\":\"2024-11-06T14:16:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html\"},\"wordCount\":918,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/rest-assured-logo.jpg\",\"keywords\":[\"JSON Assertion\",\"JSON Hamcrest\",\"JSONUnit\",\"REST-assured\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html\",\"name\":\"Asserting JSON Responses with REST-Assured in Java - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/rest-assured-logo.jpg\",\"datePublished\":\"2024-11-06T14:16:51+00:00\",\"dateModified\":\"2024-11-06T14:16:55+00:00\",\"description\":\"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/rest-assured-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/rest-assured-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/asserting-json-responses-with-rest-assured-in-java.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Asserting JSON Responses with REST-Assured in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d3eac6e45542536e961129ae0fb453e\",\"name\":\"Omozegie Aziegbe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"caption\":\"Omozegie Aziegbe\"},\"description\":\"Omos Aziegbe is a technical writer and web\\\/application developer with a BSc in Computer Science and Software Engineering from the University of Bedfordshire. Specializing in Java enterprise applications with the Jakarta EE framework, Omos also works with HTML5, CSS, and JavaScript for web development. As a freelance web developer, Omos combines technical expertise with research and writing on topics such as software engineering, programming, web application development, computer science, and technology.\",\"sameAs\":[\"https:\\\/\\\/web.facebook.com\\\/omos.aziegbe\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/omosaziegbe\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/OAziegbe\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/omozegie-aziegbe\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Asserting JSON Responses with REST-Assured in Java - Java Code Geeks","description":"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html","og_locale":"en_US","og_type":"article","og_title":"Asserting JSON Responses with REST-Assured in Java - Java Code Geeks","og_description":"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.","og_url":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/web.facebook.com\/omos.aziegbe","article_published_time":"2024-11-06T14:16:51+00:00","article_modified_time":"2024-11-06T14:16:55+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg","type":"image\/jpeg"}],"author":"Omozegie Aziegbe","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/OAziegbe","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Omozegie Aziegbe","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html"},"author":{"name":"Omozegie Aziegbe","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d3eac6e45542536e961129ae0fb453e"},"headline":"Asserting JSON Responses with REST-Assured in Java","datePublished":"2024-11-06T14:16:51+00:00","dateModified":"2024-11-06T14:16:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html"},"wordCount":918,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg","keywords":["JSON Assertion","JSON Hamcrest","JSONUnit","REST-assured"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html","url":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html","name":"Asserting JSON Responses with REST-Assured in Java - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg","datePublished":"2024-11-06T14:16:51+00:00","dateModified":"2024-11-06T14:16:55+00:00","description":"Learn how to use Java REST-assured to assert JSON responses with examples on validation, schema checks, and HTTP status testing.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/11\/rest-assured-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/asserting-json-responses-with-rest-assured-in-java.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Asserting JSON Responses with REST-Assured in Java"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d3eac6e45542536e961129ae0fb453e","name":"Omozegie Aziegbe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","caption":"Omozegie Aziegbe"},"description":"Omos Aziegbe is a technical writer and web\/application developer with a BSc in Computer Science and Software Engineering from the University of Bedfordshire. Specializing in Java enterprise applications with the Jakarta EE framework, Omos also works with HTML5, CSS, and JavaScript for web development. As a freelance web developer, Omos combines technical expertise with research and writing on topics such as software engineering, programming, web application development, computer science, and technology.","sameAs":["https:\/\/web.facebook.com\/omos.aziegbe","https:\/\/www.linkedin.com\/in\/omosaziegbe\/","https:\/\/x.com\/https:\/\/twitter.com\/OAziegbe"],"url":"https:\/\/www.javacodegeeks.com\/author\/omozegie-aziegbe"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/127342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128888"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=127342"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/127342\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/128246"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=127342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=127342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=127342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}