# How to validate the JSON response with expected JSON schema

**URL:** <https://forum.katalon.com/t/how-to-validate-the-json-response-with-expected-json-schema/14029>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [October 30, 2018, 6:33pm UTC](https://forum.katalon.com/t/how-to-validate-the-json-response-with-expected-json-schema/14029 "2018-10-30T18:33:55Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [April 8, 2019, 1:17am UTC](https://forum.katalon.com/t/how-to-validate-the-json-response-with-expected-json-schema/14029/8 "2019-04-08T01:17:39Z")

</div>

I made a demo project on Github: [https://github.com/kazurayam/MattThurmanJSONSchema](https://github.com/kazurayam/MattThurmanJSONSchema)

* * *

You shoud use `org.json.JSONArray` to parse your JSON Response, rather than `org.json.JSONObject`.

```auto
package com.ws

import org.everit.json.schema.Schema
import org.everit.json.schema.loader.SchemaLoader
import org.everit.json.schema.ValidationException
import org.json.JSONArray
import org.json.JSONObject
import org.json.JSONTokener
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.annotation.Keyword

class EveritValidator {
	@Keyword
	def verifyJsonSchema(String stringJson, String stringSchema) {
		JSONObject rawSchema = new JSONObject(new JSONTokener(stringSchema))
		Schema schema = SchemaLoader.load(rawSchema)
		try {
			
			//schema.validate(new JSONObject(stringJson))
			schema.validate(new JSONArray(stringJson))
			
			KeywordUtil.markPassed("Schema is valid - PASSED")
		} catch (ValidationException e) {
			StringBuffer outmessage = new StringBuffer()
			outmessage << e.getMessage() << "\n"
			e.getAllMessages().each { msg -> outmessage << "$msg \n" }
			KeywordUtil.markFailed(outmessage as String)
		}
	}
}

```

---

_[View the full topic](https://forum.katalon.com/t/how-to-validate-the-json-response-with-expected-json-schema/14029)._
