Initial Release
A JSON Schema Draft-07 validator implemented in InterSystems ObjectScript for IRIS.
This project provides a native ObjectScript implementation of JSON Schema validation, enabling IRIS developers to validate JSON data against JSON Schema specifications directly within their IRIS applications.
/src/JSONSchema/ into your IRIS namespaceDo $System.OBJ.CompilePackage("JSONSchema", "ck")
Do $System.OBJ.CompilePackage("Test.JSONSchema", "ck")
// Define a schema for a person object Set tSchema = { "type": "object", "required": ["name", "email", "age"], "properties": { "name": { "type": "string", "minLength": 1, "maxLength": 100 }, "email": { "type": "string", "format": "email" }, "age": { "type": "integer", "minimum": 0, "maximum": 150 }, "address": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "zipCode": {"type": "string", "pattern": "^[0-9]{5}(-[0-9]{4})?$"} } }, "tags": { "type": "array", "items": {"type": "string"}, "uniqueItems": true } }, "additionalProperties": false }// Define the data to validate
Set tData = {
"name": "John Doe",
"email": "john.doe@example.com",
"age": 35,
"address": {
"street": "123 Main St",
"city": "Springfield",
"zipCode": "12345"
},
"tags": ["developer", "team-lead"]
}// Validate the data
Set tValid = ##class(JSONSchema.Validator).Validate(tData, tSchema, .tErrors)
If tValid {
Write "Validation passed!", !
}
Else {
Write "Validation failed with ", tErrors.%Size(), " errors", !
Set tIter = tErrors.%GetIterator()
While tIter.%GetNext(.tKey, .tError) {
Write " - [", tError.dataPath, "] ", tError.message, !
}
}
ClassMethod Validate(pJSON, pSchema, Output pErrors As %DynamicArray, pSchemaVersion As %String = "draft-07") As %Boolean
Parameters:
pJSON - JSON data to validate (string, %DynamicObject, %DynamicArray, or %Stream)pSchema - JSON Schema to validate against (string, %DynamicObject, or %Stream)pErrors - Output parameter receiving array of error objectspSchemaVersion - Schema version (default: “draft-07”)Returns: 1 if valid, 0 if invalid
Each error object contains:
| Property | Description |
|---|---|
keyword |
The JSON Schema keyword that failed (e.g., “type”) |
dataPath |
JSON Pointer to the failing data location |
schemaPath |
JSON Pointer to the schema location |
message |
Human-readable error description |
iris-jsonschema/
├── src/
│ ├── JSONSchema/
│ │ ├── Validator.cls # Main entry point
│ │ ├── Context.cls # Validation context
│ │ └── Keyword/
│ │ ├── Type.cls # Type keyword validation
│ │ ├── Enum.cls # Enum keyword validation
│ │ ├── Const.cls # Const keyword validation
│ │ ├── String.cls # String keywords (minLength, maxLength, pattern, format)
│ │ ├── Numeric.cls # Numeric keywords (minimum, maximum, multipleOf, etc.)
│ │ ├── Object.cls # Object keywords (properties, required, additionalProperties, etc.)
│ │ ├── Array.cls # Array keywords (items, minItems, maxItems, uniqueItems, etc.)
│ │ ├── Combinator.cls # Schema combinators (allOf, anyOf, oneOf, not)
│ │ ├── Conditional.cls # Conditional schemas (if/then/else, dependencies)
│ │ └── Ref.cls # Schema references ($ref, definitions, $defs)
│ └── Test/JSONSchema/
│ ├── TestValidator.cls # Foundation tests
│ ├── TestTypeValidation.cls # Type keyword tests
│ ├── TestEnumConst.cls # Enum/Const tests
│ ├── TestInputFormats.cls # Input format tests
│ ├── TestContext.cls # Context tests
│ ├── TestPathTracking.cls # Path tracking tests
│ ├── TestStringKeywords.cls # String keyword tests
│ ├── TestNumericKeywords.cls # Numeric keyword tests
│ ├── TestObjectKeywords.cls # Object keyword tests
│ ├── TestArrayKeywords.cls # Array keyword tests
│ ├── TestCombinators.cls # Schema combinator tests
│ ├── TestConditional.cls # Conditional schema tests
│ └── TestRefKeyword.cls # $ref keyword tests
├── docs/ # Documentation
│ ├── stories/ # User stories
│ ├── qa/ # QA gates and assessments
│ ├── prd/ # Product requirements
│ └── architecture/ # Architecture documentation
├── module.xml # Package definition
└── README.md
Run the unit tests using IRIS terminal:
Do ##class(%UnitTest.Manager).RunTest("Test.JSONSchema")
Current test coverage: 290 tests, all passing.
MIT License
Contributions are welcome! Please read the documentation in /docs/ for architecture and coding standards.
Built with BMAD Framework for AI-assisted development.