Using JSON Schema Validator - By Rahul Kumar
Prerequisites JSON Reference : https://tools.ietf.org/html/rfc7159 JSON Schema Reference : http://json-schema.org/documentation.html
JSON Schema Validator JSON schema validator is used to validate JSON data against a JSON schema. The JSON Schema validator evaluates JSON payloads at runtime and verifies that they match a referenced JSON schema. You can match against schemas that exist in a local file or in an external URI. If the validation fails, an exception is raised with feedback about what went wrong and a reference to the original invalid payload. The JSON Schema Validator supports schema drafts of version 4 and older.
Accepted Payload Types java.lang.String, java.io.Reader, InputStream, byte[], com.fasterxml.jackson.databind.JsonNode, org.mule.module.json.JsonData If the payload type is none of the above, then the validator attempts to transform the payload into a usable type, in the following order: org.mule.module.json.JsonData com.fasterxml.jackson.databind.JsonNode java.lang.String
ConfigurationFollowing are the properties on general tab: Display Name – The display name of the connector used for display purposes in Mule flow. Schema Location – Location of the schema. It may be a web URL, file system URL etc. Dereferencing - Draft v4 defines two dereferencing modes, canonical (default) and inline. This attribute is ignored if validating a v3 draft. Schema redirects - Schema Validator supports referencing URIs to external schemas, and because one schema might reference another, the validator also supports URI redirection, so that a reference to another schema doesn’t
Schema Redirects In this example, any links to the external address http://my.site/schemas/fstab.json will redirect to the internal address resource:/org/mule/json/examples/fstab.json.
Validation Behavior If the validation is successful, then control is passed to the next processor in the chain. Otherwise a JsonSchemaValidationException is thrown containing validation feedback on the message. This exception contains a message with a detailed explanation of what went wrong, and a property called invalidJson in which the invalid payload is available on its String representation.
Precaution For performing validation the validator consumes a streaming resource (InputStream, Reader, etc), so the message payload is altered to the fully consumed JSON. So you may pass a payload of type java.io.InputStream or a java.io.Reader but you may get back a String
Flow
Thank You !!

Using JSON Schema Validator

  • 1.
  • 2.
    Prerequisites JSON Reference : https://tools.ietf.org/html/rfc7159 JSONSchema Reference : http://json-schema.org/documentation.html
  • 3.
    JSON Schema Validator JSONschema validator is used to validate JSON data against a JSON schema. The JSON Schema validator evaluates JSON payloads at runtime and verifies that they match a referenced JSON schema. You can match against schemas that exist in a local file or in an external URI. If the validation fails, an exception is raised with feedback about what went wrong and a reference to the original invalid payload. The JSON Schema Validator supports schema drafts of version 4 and older.
  • 4.
    Accepted Payload Types java.lang.String,java.io.Reader, InputStream, byte[], com.fasterxml.jackson.databind.JsonNode, org.mule.module.json.JsonData If the payload type is none of the above, then the validator attempts to transform the payload into a usable type, in the following order: org.mule.module.json.JsonData com.fasterxml.jackson.databind.JsonNode java.lang.String
  • 5.
    ConfigurationFollowing are theproperties on general tab: Display Name – The display name of the connector used for display purposes in Mule flow. Schema Location – Location of the schema. It may be a web URL, file system URL etc. Dereferencing - Draft v4 defines two dereferencing modes, canonical (default) and inline. This attribute is ignored if validating a v3 draft. Schema redirects - Schema Validator supports referencing URIs to external schemas, and because one schema might reference another, the validator also supports URI redirection, so that a reference to another schema doesn’t
  • 6.
    Schema Redirects In thisexample, any links to the external address http://my.site/schemas/fstab.json will redirect to the internal address resource:/org/mule/json/examples/fstab.json.
  • 7.
    Validation Behavior If thevalidation is successful, then control is passed to the next processor in the chain. Otherwise a JsonSchemaValidationException is thrown containing validation feedback on the message. This exception contains a message with a detailed explanation of what went wrong, and a property called invalidJson in which the invalid payload is available on its String representation.
  • 8.
    Precaution For performing validationthe validator consumes a streaming resource (InputStream, Reader, etc), so the message payload is altered to the fully consumed JSON. So you may pass a payload of type java.io.InputStream or a java.io.Reader but you may get back a String
  • 9.
  • 10.