util.jsonschema
This implements a JSON Schema validator, allowing data to be validated against a declarative schema that specifies types and various properties.
Implements most, but not all of JSON Schema core and Validation.
Example
local schema = {
type = "object";
= { "name"; "version" };
required = {
properties = { type = "string" };
name = { type = "string" };
version = { type = "string" };
os };
};
local data = { name = "Prosody"; version = 12 };
if jsonschema.validate(schema, data) then
print("OK")
else
print("Wrong!")
end
Implementation Notes
- Objects and Arrays are not distinct types in Lua. Notably empty arrays and empty objects are indistinguishable.
$anchor
,$dynamicAnchor
,$dynamicRef
are not implemented.- Deep comparison of objects and arrays is not implemented, affecting
e.g.
const
,enum
anduniqueItems
. minProperties
andmaxProperties
are not implemented.$id
is not used.- Referencing external schemas is not implemented.
pattern
is not implemented as it requires RegEx, not available in Lua without a 3rd party module. Instead aluaPattern
that uses Lua Patterns is supported.multipleOf
and floating point numbers are unreliable.