WebAssembly bindings for checking compatibility of evolving JSON Schemas and generating example values from JavaScript.
npm install jsoncompat@0.3.1import init, { check_compat, generate_value, validator_for } from "jsoncompat";
await init();
const oldSchema = '{"type":"string"}';
const newSchema = '{"type":["string","null"]}';
const ok = check_compat(oldSchema, newSchema, "deserializer");
const valueJson = generate_value(newSchema, 5);
const validator = validator_for(newSchema);
const valueOk = validator.is_valid(valueJson);check_compat(old_schema_json, new_schema_json, role) -> booleanaccepts"serializer","deserializer", or"both"forrole.generate_value(schema_json, depth) -> stringreturns one generated JSON value encoded as a string.validator_for(schema_json) -> Validatorparses a schema once and returns a reusable validator.Validator.is_valid(instance_json) -> booleanvalidates a JSON string against the parsed schema.
Both functions accept schemas as JSON strings and throw string-backed
wasm-bindgen errors for invalid JSON, invalid schemas, hard unsupported
compatibility features, known-unsatisfiable schemas, or retry exhaustion.
MIT