safe-validate-json-schema
v1.1.1
Published
Validate JSON against a JSON Schema and return human-friendly, prioritized fix suggestions (masks secrets).
Maintainers
Readme
safe-validate-json-schema
A safe and user-friendly JSON Schema validator with helpful error messages.
Install
npm i -D safe-validate-json-schema
# or globally
npm i -g safe-validate-json-schemaUsage (programmatic)
import { validateWithFriendlyErrors } from 'safe-validate-json-schema';
const schema = { type: 'object', required: ['name'], properties: { name: { type: 'string' }, age: { type: 'number' } } };
const data = { name: 123, extra: true };
const res = validateWithFriendlyErrors(schema, data);
if (!res.valid) console.log(res.errors);Usage (CLI)
safe-validate-json-schema --schema schema.json --data data.json