@lowdep/json-validate
v1.0.0
Published
Validate JSON data against a JSON Schema (draft-07 core) — readable errors, CI-friendly, zero dependencies
Maintainers
Readme
json-validate
Validate JSON data against a JSON Schema (draft-07 core) with readable error messages. Zero dependencies.
The natural companion to json-schema-gen: generate a schema from a sample, then enforce it in CI. Unlike ajv-cli, this pulls in no dependencies.
Install
npm install -g json-validateOr without installing:
npx json-validate schema.json data.jsonUsage
json-validate schema.json data.json # Validate one file
json-validate schema.json user1.json user2.json # Validate several
json-validate -s schema.json data.json --quiet # Exit code only
json-validate schema.json data.json --json # Machine-readableExample
schema.json:
{
"type": "object",
"required": ["id", "email", "age"],
"properties": {
"id": { "type": "string", "format": "uuid" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0, "maximum": 120 },
"role": { "enum": ["admin", "user", "guest"] }
},
"additionalProperties": false
}data.json:
{ "id": "not-a-uuid", "email": "bad", "age": 200, "role": "wizard", "extra": true }Running json-validate schema.json data.json:
json-validate schema: schema.json
✗ data.json 5 errors
.id is not a valid uuid
.email is not a valid email
.age must be <= 120 (is 200)
.role must be one of ["admin","user","guest"]
(root) additional property 'extra' is not allowed
0 valid 1 invalidSupported Keywords
| Category | Keywords |
|---|---|
| Core | type, enum, const |
| Object | required, properties, patternProperties, additionalProperties, minProperties, maxProperties |
| Array | items (incl. tuples), minItems, maxItems, uniqueItems |
| Number | minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf |
| String | minLength, maxLength, pattern, format |
| Combinators | allOf, anyOf, oneOf, not |
Formats: date-time, date, time, email, uri, uuid, ipv4, ipv6, hostname
CI Integration
- name: Validate config against schema
run: npx json-validate config.schema.json config.json --quietExit codes:
0— all data files valid1— at least one invalid2— file missing or malformed JSON
Scope
This validates the draft-07 core keywords listed above — covering the vast majority of real-world schemas. It does not resolve $ref/$defs or remote references; keep schemas self-contained. For full draft-2020-12 + $ref resolution, use ajv.
License
MIT
Keywords
json schema validator · validate json · ajv alternative · ajv-cli alternative · json validation · draft-07 · schema check · validate against schema · zero dependencies · ci
Built to solve, shared to help — Rushabh Shah 🛠️✨
One of 40+ zero-dependency developer CLI tools — no node_modules, ever.
