Sample Web UI Added
A JSON Schema validator for Draft-07 and 2020-12 implemented in InterSystems ObjectScript for IRIS.
Contest Submission: Created for submission to the InterSystems “Bringing Ideas to Reality” Contest 2025 (contest details). Submitted in response to: https://ideas.intersystems.com/ideas/DPI-I-769
This project provides a native ObjectScript implementation of JSON Schema validation, enabling IRIS developers to validate JSON data against JSON Schema Draft-07 and 2020-12 specifications directly within their IRIS applications.
$schema keyword/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
│ ├── TestRESTEndpoint.cls # REST API tests
│ └── Test2020Keywords.cls # JSON Schema 2020-12 tests
├── docs/ # Documentation
│ ├── stories/ # User stories
│ ├── qa/ # QA gates and assessments
│ ├── prd/ # Product requirements
│ └── architecture/ # Architecture documentation
├── module.xml # Package definition
└── README.md
An Angular-based web application provides a user-friendly interface for JSON Schema validation.
# Navigate to the Angular project directory cd web/jsonschema-validatorInstall dependencies
npm install
The Angular app uses a proxy configuration to forward API requests to IRIS.
# Start the development server with API proxy
cd web/jsonschema-validator
npm start
The application will be available at http://localhost:4200
The development server proxies /api requests to IRIS. The proxy configuration is in proxy.conf.json:
{
"/api": {
"target": "http://localhost:52773",
"secure": false,
"changeOrigin": true
}
}
To use a different IRIS server, update the target URL in proxy.conf.json.
API settings are configured in the environment files:
| File | Purpose |
|---|---|
src/environments/environment.ts |
Development settings |
src/environments/environment.prod.ts |
Production settings |
# Run unit tests cd web/jsonschema-validator npm testRun tests with code coverage
npm test -- --no-watch --code-coverage
Current test coverage: 78 tests, all passing.
# Build for production cd web/jsonschema-validator npm run buildOutput is generated in dist/jsonschema-validator/
| Feature | Description |
|---|---|
| Split-pane Editors | Side-by-side JSON and Schema editors with CodeMirror 6 |
| Syntax Highlighting | Full JSON syntax highlighting with error detection |
| Schema Version Selector | Choose between Draft-07 and 2020-12 |
| Validation Results | Green ✓ Valid or Red ✗ Invalid with error details |
| Error Navigation | Click errors to jump to the relevant line in the JSON editor |
| Keyboard Shortcuts | Ctrl+Enter to trigger validation |
The JSON Schema Validator also provides a REST API for programmatic access.
Configure the CSP web application using the helper class:
// Create the /api/jsonschema web application Do ##class(JSONSchema.REST.Setup).CreateApplication()// Check if application exists
Write ##class(JSONSchema.REST.Setup).ApplicationExists()
// Delete application (if needed)
Do ##class(JSONSchema.REST.Setup).DeleteApplication()
| Method | Path | Description |
|---|---|---|
| POST | /api/jsonschema/validate |
Validate JSON against a schema |
| OPTIONS | /api/jsonschema/validate |
CORS preflight |
{
"jsonInput": "",
"schemaInput": "",
"schemaVersion": "draft-07" // Optional, defaults to "draft-07"
}
{
"valid": true,
"errors": [],
"schemaVersion": "draft-07"
}
# Valid JSON example curl -X POST http://localhost:52773/api/jsonschema/validate \ -H "Content-Type: application/json" \ -d '{ "jsonInput": "{\"name\": \"John\", \"age\": 30}", "schemaInput": "{\"type\": \"object\", \"properties\": {\"name\": {\"type\": \"string\"}, \"age\": {\"type\": \"integer\"}}}" }'Response: {"valid":1,"errors":[],"schemaVersion":"draft-07"}
# Invalid JSON example (wrong type)
curl -X POST http://localhost:52773/api/jsonschema/validate \
-H "Content-Type: application/json" \
-d '{
"jsonInput": "\"not an object\"",
"schemaInput": "{\"type\": \"object\"}"
}'
# Response: {"valid":0,"errors":[{"keyword":"type","dataPath":"#","schemaPath":"#/type","message":"Expected type 'object' but got 'string'"}],"schemaVersion":"draft-07"}
$body = @{ jsonInput = '{"name": "John", "age": 30}' schemaInput = '{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}' } | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:52773/api/jsonschema/validate" `
-Method POST -ContentType "application/json" -Body $body
Run the unit tests using IRIS terminal:
Do ##class(%UnitTest.Manager).RunTest("Test.JSONSchema")
Current test coverage: 317 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.