Validates a JSON string against a JSON Schema (also given as a string) and returns an array of violation structs, each with message (the human-readable problem) and pointerToViolation (a JSON pointer to the offending member, "#" for the document root). The array is empty when the JSON is valid. When throwOnError is true and there are violations, an error is thrown with the first violation's message instead. baseUri resolves relative schema references. Available when the jsonschema cargo feature is enabled.
validateJson(json, schema [, throwOnError] [, baseUri])
→ returns array
falsetruefalseA valid document returns an empty array; an invalid one lists the violations.
schema = serializeJSON({ type: "object", properties: { name: { type: "string" } }, required: ["name"] });
writeDump(arrayLen(validateJson(serializeJSON({name: "Alex"}), schema)));
errors = validateJson(serializeJSON({age: 30}), schema);
writeDump(errors[1].message);
Expected Result: 0 name is a required property
Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.