Binding to XML, JSON, and YAML

Note: This section of the specification is still a work in progress.

XML, JSON, and YAML each use specialized terminology and format primitives. As a notation for an object-based data, YAML is fairly similar to JSON, while XML is quite different to the other two. While all data format describe tree structures (directed graphs), each format (with its implicit data model) has its particular design, which requires specification in detail.

For example, a data point represented as an attribute on an element in XML, for example, might be a string property on a data object in JSON. The metaschema moderates this distinction by providing rules regarding its own semantic constructs and how they are to be represented in the target format. As a result, a mapping between JSON and XML concepts is implicitly available through the corresponding metaschema.

Within Metaschema-based models, all constructs are optional unless marked otherwise.

MetaschemaXMLJSON and YAML
AssemblyAn element with element contentAn object, either a property or a member of an array property
Field (with no flags)A single element with text contentString property
Field with one or more flagsAn element with text content, flags as attributesAn object property with a designated property for its nominal string value as well as properties for its flags
FlagAttributeString property
Flag with designated data typeAttribute with lexical constraints per typeString property with lexical constraints per type, or typed property such as number or URI (per type)
Field as-type='simple-markup', no flags permittedAn element permitting mixed content inlineString property or map with string property, parsable as markdown (line only)
Field as='complex-markup', flag(s) permittedAn element permitting mixed content inlineObject property with RICHTEXT String property or object with string property, parsable as markdown (full blocks)
<any> in assembly modelChild elements from foreign namespaces (xs:any namespace="##other")Additional object properties not declared in the model (additionalProperties: true)

XML Representational Form

Flag Instance

In XML, a flag instance is represented as an attribute.

<instance-effective-name flag-name="flag value"/>

Field Instance

In XML, a field is represented in two possible ways:

  1. As an XML element.

    The representational form of a field varies based on the presence of child flags.

    <field-name>field value</field-name>
    

    or

    <field-name flag="flag1 value">field value</field-name>
    

    The form immediately above is used when the field has a child flag instance.

  2. As a text value in an unwrapped form.

    <some-assembly>field value</some-assembly>
    

    This form is only allowed when a field has no child flags.

<any> Instance

When an assembly definition declares <any/> in its model, the XML representation permits child elements from foreign namespaces after all declared model instance elements.

In a generated XML Schema, this is represented as:

<xs:any namespace="##other" processContents="lax"
       minOccurs="0" maxOccurs="unbounded"/>

The namespace="##other" restriction limits unmodeled elements to namespaces other than the assembly’s target namespace. The processContents="lax" setting means validation of unmodeled elements is attempted only if a schema for the element’s namespace is available.

JSON Representational Form

Flag Instance

In JSON a flag instance is represented as an object member with an associated value.

{
  "flag-name": "flag value"
}

<any> Instance

When an assembly definition declares <any/> in its model, the JSON representation permits additional properties on the assembly’s object beyond those declared in the model.

In a generated JSON Schema, this is represented by setting additionalProperties to true on the assembly’s object schema:

{
  "type": "object",
  "properties": { ... },
  "additionalProperties": true
}

This allows any property name and value to appear alongside the declared properties.

YAML Representational Form

Flag Instance

The YAML representation is similar to JSON, where a tagged value is used to represent a flag.

flag-name: flag value

<any> Instance

The YAML representation of <any/> is identical to the JSON representation, since YAML is a superset of JSON. Additional mapping keys on the assembly’s mapping represent unmodeled content.