Validates JSON against a given schema.

Added in 2.2.1


Syntax

Result = SRP_Json(Handle, "Validate", Schema, Json)

Returns

Returns 1 if JSON is validated or an error string if it fails to validate.

Parameters

ParameterDescription
HandleHandle to JSON Entity. Optional.
SchemaThe JSON Schema. Required.
JsonThe unparsed JSON to validate. Optional.

Remarks

The Validate service validates JSON against a schema. There are two ways to do this. If you already parsed your JSON into a handle, you can validate that JSON by passing the handle and leaving the Json parameter blank. If you have unparsed JSON you want to validate, then pass "" as the handle and pass the unparsed JSON via the Json property. In either case, this service will return "1" if the JSON is successfully validated. If the validation fails, a string is returned explaining the error.

Visit json-schema.org to learn about schemas. This service uses Draft-07 of Json Schema.

Example

// Validate unparsed json
Result = SRP_Json("", "Validate", Schema, Json)

// Validate parsed json
If SRP_Json(Handle, "Parse", Json)
    Result = SRP_Json(Handle, "Validate", Schema)
    SRP_Json(Handle, "Release")
End
  • No labels