DEV Community
Follow
I Built a Browser-Only JSON Schema Validator — Draft-07, $ref, allOf/anyOf/oneOf, if/then/else, 173 Tests
A new, zero-dependency browser tool has been developed to validate JSON Schema Draft-07 specifications from scratch. This tool is designed for quick schema checking, debugging, and learning without requiring a Node.js project setup. It implements a comprehensive subset of Draft-07 keywords including type system, enumeration, string, number, array, object, combining, conditionals, and references. The validator also supports common formats like email, URI, date, and UUID. Each validation error provides the JSON path to the failing value, a human-readable message, and a keyword badge indicating the specific rule that failed.The tool's architecture is based on a single recursive function that validates data against a schema. It prioritizes type checking, returning early if the data type doesn't match the schema's expected type. The validator also handles compatibility with older Draft-04 versions for exclusive minimum and maximum keywords. Local $ref resolutions are managed by traversing the JSON pointer path within the root schema, with $ref keywords short-circuiting all other sibling keywords as per the specification.Conditional validation using if/then/else, a key feature of Draft-07, is implemented to allow for more dynamic schema rules. The tool includes over 170 tests covering all implemented functions and keywords, ensuring accuracy and reliability. The user interface features a split-pane layout for JSON and schema, with results displayed below. Parse errors are shown immediately per pane. Error cards are designed to be informative, mirroring the formatting of popular libraries like ajv. Three built-in examples are available to facilitate immediate exploration. The tool is accessible online at json-schema-validator-dev.pages.dev and is part of a growing collection of browser-only developer tools.