Skip to main content

Assert Valid JSON Schema

Legacy Documentation
You're viewing legacy documentation for API Fortress (deployed via an on-premises container). To view documentation for the new SaaS version of API Fortress — now known as Sauce Labs API Testing and Monitoring (with Sauce Connect tunnels) — see API Testing on the Sauce Labs Cloud.

Parameters

NameType/ValueRequired
ExpressionExpressionYes
JsonSchemaJSON schema definitionYes
CommentStringNo
  • Expression: The path to the element we want to operate on (e.g., payload.ProductID). See Expression for more details.
  • JsonSchema: The JSON schema definition. This will be used to validate the JSON passed in the expression field. See below for an example.
  • Comment: Add comment messages in the form of a string data type.

JSON Schema Example

Sample JSON

{
"rectangle": {
"a": 15,
"b": 5
}
}

Sample Schema

{
"type": "object",
"properties": {
"rectangle": {
"$ref": "#/definitions/Rectangle"
}
},
"definitions": {
"size": {
"type": "number",
"minimum": 0
},
"Rectangle": {
"type": "object",
"properties": {
"a": {
"$ref": "#/definitions/size"
},
"b": {
"$ref": "#/definitions/size"
}
}
}
}
}

Code View Example

<set var="json_success" lang="template">
<![CDATA[{ "rectangle" : { "a" : 15, "b" : 5 } }]]>
</set>
<assert-valid-jsonschema expression="json_success">
<![CDATA[{ "type" : "object", "properties" : { "rectangle" : {"$ref" :
"#/definitions/Rectangle" } }, "definitions" : { "size" : { "type" : "number",
"minimum" : 0 }, "Rectangle" : { "type" : "object", "properties" : { "a" :
{"$ref" : "#/definitions/size"}, "b" : {"$ref" : "#/definitions/size"} } } }
}]]>
</assert-valid-jsonschema>