Schema Version 3
Morphir IR JSON Schema for format version 3 (Current)
This directory contains formal JSON schema specifications for all supported format versions of the Morphir IR (Intermediate Representation).
Tag Capitalization:
"library" → "Library""public"/"private" → "Public"/"Private""variable" → "Variable", "reference" → "Reference", etc.Structure Changes:
{"name": ..., "def": ...} objects to [modulePath, accessControlled] arraysTag Capitalization:
"apply" → "Apply", "lambda" → "Lambda", etc."as_pattern" → "AsPattern", "wildcard_pattern" → "WildcardPattern", etc."bool_literal" → "BoolLiteral", "string_literal" → "StringLiteral", etc.The schemas can be used to validate Morphir IR JSON files. Note that due to the complexity and recursive nature of these schemas, validation can be slow with some validators.
pip install jsonschema pyyaml
python3 << 'EOF'
import json
import yaml
from jsonschema import validate
# Load schema
with open('morphir-ir-v3.yaml', 'r') as f:
schema = yaml.safe_load(f)
# Load Morphir IR JSON
with open('morphir-ir.json', 'r') as f:
data = json.load(f)
# Validate
validate(instance=data, schema=schema)
print("✓ Valid Morphir IR")
EOF
npm install -g ajv-cli ajv-formats
# Convert YAML to JSON first
python3 -c "import yaml, json; \
json.dump(yaml.safe_load(open('morphir-ir-v3.yaml')), open('morphir-ir-v3.json', 'w'))"
# Validate
ajv validate -s morphir-ir-v3.json -d morphir-ir.json
For a quick check without full validation, you can verify basic structure:
import json
def check_morphir_ir(filepath):
with open(filepath) as f:
data = json.load(f)
# Check format version
version = data.get('formatVersion')
assert version in [1, 2, 3], f"Unknown format version: {version}"
# Check distribution structure
dist = data['distribution']
assert isinstance(dist, list) and len(dist) == 4
assert dist[0] in ["library", "Library"], f"Unknown distribution type: {dist[0]}"
# Check package definition
pkg_def = dist[3]
assert 'modules' in pkg_def
print(f"✓ Basic structure valid: Format v{version}, {len(pkg_def['modules'])} modules")
check_morphir_ir('morphir-ir.json')
These schemas can be used to:
The schemas are written in YAML format for better readability and include:
When updating the IR format:
Morphir IR JSON Schema for format version 3 (Current)
Morphir IR JSON Schema for format version 2
Morphir IR JSON Schema for format version 1
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.