Schema Annotations for Linked Avro Data (SALAD)

8.9.20260327095315 · active · verified Mon Apr 13

Schema Salad (SALAD) is a schema language for describing JSON or YAML structured linked data documents. It provides rules for preprocessing, structural validation, and hyperlink checking, and supports rich data modeling features like inheritance, template specialization, object identifiers, and references. It also enables documentation and code generation, and transformation to RDF, bridging document-oriented data modeling with the Semantic Web. The current version is 8.9.20260327095315, and it appears to have a frequent release cadence, often multiple patch releases per month, indicating active development.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load and validate a SALAD schema and then use that schema to validate a data document. It creates temporary YAML files for the schema and document content, then uses `schema_salad.schema.load_and_validate` and `schema_salad.ref_resolver.Loader` to perform the validation.

import os
import json
from schema_salad.schema import load_and_validate
from schema_salad.ref_resolver import Loader

# Define a simple SALAD schema (YAML string)
schema_content = """
$schema: http://json-schema.org/draft-07/schema#
$id: https://example.com/myschema.yml
type: record
name: MyRecord
documentRoot: true
fields:
  - name: id
    type: string
    jsonldPredicate: '@id'
  - name: message
    type: string
  - name: count
    type: int
"""

# Define a document to validate (YAML string)
document_content = """
id: 'my_first_doc'
message: "Hello, SALAD!"
count: 42
"""

# Save schema and document to temporary files
schema_file = 'temp_schema.yml'
document_file = 'temp_document.yml'

with open(schema_file, 'w') as f:
    f.write(schema_content)
with open(document_file, 'w') as f:
    f.write(document_content)

# Create a Loader instance
loader = Loader({})

# Load and validate the schema itself
print(f"Validating schema: {schema_file}")
schema_salad_obj, _, _ = load_and_validate(schema_file, loader)
print("Schema is valid.")

# Load and validate the document against the schema
print(f"Validating document: {document_file}")
try:
    validated_doc, _ = load_and_validate(schema_file, document_file, loader)
    print("Document is valid.")
    print("Validated document (as Python object):")
    print(json.dumps(validated_doc, indent=2))
except Exception as e:
    print(f"Document validation failed: {e}")

# Clean up temporary files
os.remove(schema_file)
os.remove(document_file)

view raw JSON →