Add @stdlib/json_schema module for JSON Schema validation#443
Open
nbeerbower wants to merge 1 commit into
Open
Add @stdlib/json_schema module for JSON Schema validation#443nbeerbower wants to merge 1 commit into
nbeerbower wants to merge 1 commit into
Conversation
Pure Hemlock module built on @stdlib/json that validates values against JSON Schema-like definitions. Designed for validating LLM responses, API payloads, and configuration data. Supported schema keywords: - Type: type (with union types), enum, const - Numbers: minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf - Strings: minLength, maxLength - Arrays: items, minItems, maxItems, uniqueItems - Objects: properties, required, additionalProperties, minProperties, maxProperties - Composition: allOf, anyOf, oneOf, not, if/then/else Includes builder helpers (string_type, object_type, nullable, etc.), validate_json for direct string input, and format_errors for display. 8 test files covering types, numbers, strings, arrays, objects, composition, builders, and JSON string validation. https://claude.ai/code/session_01Vrk4CoN6sAZBCRxvzyuBpY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
@stdlib/json_schemamodule to the standard library, bringing JSON Schema validation capabilities to Hemlock. This is particularly useful for validating structured output from LLMs, API responses, configuration files, and user input.Key Changes
stdlib/json_schema.hml- Pure Hemlock implementation of JSON Schema Draft 7 validation (400+ lines)stdlib/docs/json_schema.mdwith API reference, examples, and use casesstring_type,object_type,array_type,nullable,enum_type, etc.)validate(value, schema)- Returns detailed error information with pathsis_valid(value, schema)- Boolean-only checkvalidate_json(json_str, schema)- Parse and validate in one callformat_errors(errors)- Human-readable error formattingImplementation Details
@stdlib/jsonwith no external dependenciesusers[1].name)Use Cases
https://claude.ai/code/session_01Vrk4CoN6sAZBCRxvzyuBpY