{
    "id": "https://raw.githubusercontent.com/sdmx-twg/sdmx-json/master/data-message/tools/schemas/1.0/sdmx-json-data-schema.json",
    "$schema": "http://json-schema.org/schema#",
    "description": "Schema for SDMX-JSON data message",
    "type": "object",
    "properties": {
        "meta": {
			"description": "A meta object that contains non-standard meta-information and basic technical information about the message, such as when it was prepared and who has sent it.",
            "$ref": "#/definitions/meta"
        },
        "data": {
			"description": "Data contains the message's “primary data”.",
            "type": "object",
            "properties": {
                "structure": {"$ref": "#/definitions/structure"},
                "dataSets": {
                    "type": "array",
                    "items": {"$ref": "#/definitions/dataSet"}
                }
            }
        },
        "errors": {
			"description": "Errors field is an array of error objects. When appropriate provides a list of error messages in addition to RESTful web services HTTP error status codes.",
            "type": "array",
            "items": {"$ref": "#/definitions/error"}
        }
    },
    "definitions": {
        "meta": {
			"description": "A meta object that contains non-standard meta-information and basic technical information about the message, such as when it was prepared and who has sent it.",
            "type": "object",
            "required": [
                "id",
                "prepared",
                "sender"
            ],
            "properties": {
                "schema": {
					"description": "Contains the URL to the schema allowing to validate the message. This also allows identifying the version of SDMX-JSON format used in this message. Providing the link to the SDMX-JSON schema is recommended.",
                    "type": "string",
                    "format": "uri"
                },
                "id": {
					"description": "Unique string assigned by the sender that identifies the message for further references.",
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_@$-]+$"
                },
                "test": {
					"description": "Test indicates whether the message is for test purposes or not. False for normal messages.",
                    "type": "boolean"
                },
                "prepared": {
					"description": "A timestamp indicating when the message was prepared. Values must follow the ISO 8601 syntax for combined dates and times, including time zone.",
                    "type": "string",
                    "format": "date-time"
                },
                "contentLanguages": {
					"description": "Array of strings containing the identifyer of all languages used anywhere in the message for localized elements, and thus the languages of the intended audience, representaing in an array format the same information than the http Content-Language response header, e.g. \"en, fr-fr\". See IETF Language Tags: https://tools.ietf.org/html/rfc5646#section-2.1. The array's first element indicates the main language used in the message for localized elements. The usage of this property is recommended.",
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern": "^(?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))$|^((?:[a-z]{2,3}(?:(?:-[a-z]{3}){1,3})?)|[a-z]{4}|[a-z]{5,8})(?:-([a-z]{4}))?(?:-([a-z]{2}|[0-9]{3}))?((?:-(?:[0-9a-z]{5,8}|[0-9][0-9a-z]{3}))*)?((?:-[0-9a-wy-z](?:-[0-9a-z]{2,8})+)*)?(-x(?:-[0-9a-z]{1,8})+)?$|^(x(?:-[0-9a-z]{1,8})+)$"
                    }
                },
				"name": {
					"description": "Name provides a name for the transmission. Multiple instances allow for parallel language values.",
					"$ref": "#/definitions/localisedBestMatchText"
				},
				"names": {
					"description": "Name provides a name for the transmission. Multiple instances allow for parallel language values.",
					"$ref": "#/definitions/localisedText"
				},
                "sender": {
					"description": "Name provides a name for the transmission. Multiple instances allow for parallel language values.",
                    "$ref": "#/definitions/party"
                },
                "receivers": {
                    "description": "Receiver is information about the part(y/ies) that is/are the intended recipient(s) of the message. This can be useful if the WS requires authentication.",
                    "type": "array",
                    "items": {"$ref": "#/definitions/party"}
                },
                "links": {"$ref": "#/definitions/links"}
            }
        },
        "party": {
            "type": "object",
            "required": ["id"],
            "properties": {
                "id": {
					"description": "The id holds the identification of the party.",
                    "type": "string",
                    "pattern": "^[A-Za-z0-9_@$-]+$"
                },
                "name": {
					"description": "Name is a human-readable name of the party.",
                    "$ref": "#/definitions/localisedBestMatchText"
                },
                "names": {
					"description": "List of localised human-readable name of the party.",
                    "$ref": "#/definitions/localisedText"
                },
                "contact": {
					"description": "Contact provides contact information for the party in regard to the transmission of the message.",
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": ["name"],
                        "properties": {
                            "name": {
                                "description": "Name contains a humain-readable name for the contact.",
                                "$ref": "#/definitions/localisedBestMatchText"
                            },
                            "names": {
                                "description": "Name contains a humain-readable name for the contact.",
                                "$ref": "#/definitions/localisedText"
                            },
                            "department": {
                                "description": "Department is a humain-readable designation of the organisational structure by a linguistic expression, within which the contact person works.",
                                "$ref": "#/definitions/localisedBestMatchText"
                            },
                            "departments": {
                                "description": "Department is a humain-readable designation of the organisational structure by a linguistic expression, within which the contact person works.",
                                "$ref": "#/definitions/localisedText"
                            },
                            "role": {
                                "description": "Role is the responsibility of the contact person with respect to the object for which this person is the contact.",
                                "$ref": "#/definitions/localisedBestMatchText"
                            },
                            "roles": {
                                "description": "Role is the responsibility of the contact person with respect to the object for which this person is the contact.",
                                "$ref": "#/definitions/localisedText"
                            },
                            "telephones": {
                                "type": "array",
                                "items": {
                                    "description": "Telephone holds the telephone number for the contact person.",
                                    "type": "string"
                                }
                            },
                            "faxes": {
                                "type": "array",
                                "items": {
                                    "description": "Fax holds the fax number for the contact person.",
                                    "type": "string"
                                }
                            },
                            "x400s": {
                                "type": "array",
                                "items": {
                                    "description": "X400 holds the X.400 address for the contact person.",
                                    "type": "string"
                                }
                            },
                            "uris": {
                                "type": "array",
                                "items": {
                                    "description": "URI holds an information URL for the contact person.",
                                    "type": "string",
                                    "format": "uri"
                                }
                            },
                            "emails": {
                                "type": "array",
                                "items": {
                                    "description": "Email holds the email address for the contact person.",
                                    "type": "string",
                                    "format": "email"
                                }
                            }
                        }
                    }
                }
            }
        },
        "localisedBestMatchText": {
            "type": "string",
            "description": "localisedBestMatchText is a reusable element, used for providing a human-readable best-language-match texts."
        },
        "localisedText": {
            "description": "localisedText provides for a set of language-specific alternates to be provided for any human-readable constructs in the instance. ",
            "type": "object",
            "patternProperties": {"^(?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))$|^((?:[a-z]{2,3}(?:(?:-[a-z]{3}){1,3})?)|[a-z]{4}|[a-z]{5,8})(?:-([a-z]{4}))?(?:-([a-z]{2}|[0-9]{3}))?((?:-(?:[0-9a-z]{5,8}|[0-9][0-9a-z]{3}))*)?((?:-[0-9a-wy-z](?:-[0-9a-z]{2,8})+)*)?(-x(?:-[0-9a-z]{1,8})+)?$|^(x(?:-[0-9a-z]{1,8})+)$": {"type": "string"}}
        },
        "error": {
			"description": "Error describes the structure of an error or warning message.",
            "type": "object",
            "required": ["code"],
            "properties": {
                "code": {
					"description": "Provides a code number for the error message. Code numbers are defined in the SDMX 2.1 Web Services Guidelines.",
                    "type": "number"
                },
                "title": {
					"description": "Title contains the title of the message, in best-match language value. A short, human-readable localised summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.",
                    "$ref": "#/definitions/localisedBestMatchText"
                },
                "titles": {
					"description": "Title contains the title of the message, in parallel language values. A list of short, human-readable localised summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.",
                    "$ref": "#/definitions/localisedText"
                },
                "detail": {
					"description": "Detail contains the detailed text of the message, in best-match language value. A human-readable localised explanation specific to this occurrence of the problem. Like title, this field’s value can be localized. It is fully customizable by the service providers and should provide enough detail to ease understanding the reasons of the error.",
                    "$ref": "#/definitions/localisedBestMatchText"
                },
                "details": {
					"description": "Detail contains the detailed text of the message, in parallel language values. A list of human-readable localised explanations specific to this occurrence of the problem. Like title, this field’s value can be localized. It is fully customizable by the service providers and should provide enough detail to ease understanding the reasons of the error.",
                    "$ref": "#/definitions/localisedText"
                },
                "links": {
					"description": "Links field is an array of link objects. If appropriate, a collection of links to additional external resources for the error.",
                    "$ref": "#/definitions/links"
                }
            }
        },
        "links": {
            "description": "Links field is an array of link objects. If appropriate, a collection of links to additional external resources for the header.",
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "href": {"$ref": "#/definitions/uri"},
                    "rel": {
                        "description": "Relationship of the object to the external resource. See semantics below. Use 'self' to indicate the urn to the parent object.",
                        "anyOf": [
                            {"type": "string"},
                            {
                                "description": "structure: provides a reference to the data structure or metadata structure definition depending on the context. Other SDMX artefact types can be specified, e.g. dataflow, provisionagreement, etc. For the others please see: https://tools.ietf.org/rfc/rfc5988.txt",
                                "type": "string",
                                "enum": [
                                    "agencyscheme",
                                    "alternate",
                                    "appendix",
                                    "bookmark",
                                    "categorisation",
                                    "categoryscheme",
                                    "chapter",
                                    "codelist",
                                    "conceptscheme",
                                    "constraint",
                                    "contents",
                                    "copyright",
                                    "current",
                                    "dataflow",
                                    "dataconsumerscheme",
                                    "dataproviderscheme",
                                    "describedby",
                                    "edit",
                                    "edit-media",
                                    "enclosure",
                                    "first",
                                    "glossary",
                                    "help",
                                    "hierarchicalcodelist",
                                    "hub",
                                    "index",
                                    "last",
                                    "latest-version",
                                    "license",
                                    "metadataflow",
                                    "next",
                                    "next-archive",
                                    "organisationunitscheme",
                                    "payment",
                                    "prev",
                                    "predecessor-version",
                                    "previous",
                                    "prev-archive",
                                    "process",
                                    "provisionagreement",
                                    "related",
                                    "replies",
                                    "reportingtaxonomy",
                                    "section",
                                    "self",
                                    "service",
                                    "start",
                                    "structure",
                                    "structureset",
                                    "stylesheet",
                                    "subsection",
                                    "successor-version",
                                    "up",
                                    "version-history",
                                    "via",
                                    "working-copy",
                                    "working-copy-of"
                                ]
                            }
                        ]
                    },
                    "urn": {
                        "description": "The urn holds a valid SDMX Registry URN (see SDMX Registry Specification for details).",
                        "$ref": "#/definitions/urn"
                    },
                    "uri": {
                        "description": "The uri attribute holds a URI that contains a link to additional information about the resource, such as a web page. This uri is not an SDMX resource.",
                        "$ref": "#/definitions/uri"
                    },
                    "title": {"$ref": "#/definitions/localisedBestMatchText"},
                    "titles": {"$ref": "#/definitions/localisedText"},
                    "type": {
                        "description": "A hint about the type of representation returned by the link.",
                        "type": "string"
                    },
                    "hreflang": {
                        "description": "The natural language of the external link, the same as used in the HTTP Accept-Language request header.",
                        "type": "string",
                        "pattern": "^(?:(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))$|^((?:[a-z]{2,3}(?:(?:-[a-z]{3}){1,3})?)|[a-z]{4}|[a-z]{5,8})(?:-([a-z]{4}))?(?:-([a-z]{2}|[0-9]{3}))?((?:-(?:[0-9a-z]{5,8}|[0-9][0-9a-z]{3}))*)?((?:-[0-9a-wy-z](?:-[0-9a-z]{2,8})+)*)?(-x(?:-[0-9a-z]{1,8})+)?$|^(x(?:-[0-9a-z]{1,8})+)$"
                    }
                },
                "anyOf": [
                    {"required": [
                        "href",
                        "rel"
                    ]},
                    {"required": [
                        "urn",
                        "rel"
                    ]}
                ]
            }
        },
        "structure": {
            "type": "object",
            "required": ["dimensions"],
            "properties": {
                "links": {"$ref": "#/definitions/links"},
                "name": {"$ref": "#/definitions/localisedBestMatchText"},
                "names": {"$ref": "#/definitions/localisedText"},
                "description": {"$ref": "#/definitions/localisedBestMatchText"},
                "descriptions": {"$ref": "#/definitions/localisedText"},
                "dimensions": {
                    "type": "object",
                    "properties": {
                        "dataSet": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/dimension"},
                            "uniqueItems": true
                        },
                        "series": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/dimension"},
                            "uniqueItems": true
                        },
                        "observation": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/dimension"},
                            "uniqueItems": true
                        }
                    }
                },
                "attributes": {
                    "type": "object",
                    "properties": {
                        "dataSet": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/attribute"},
                            "uniqueItems": true
                        },
                        "series": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/attribute"},
                            "uniqueItems": true
                        },
                        "observation": {
                            "type": "array",
                            "items": {"$ref": "#/definitions/attribute"},
                            "uniqueItems": true
                        }
                    }
                },
                "annotations": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "title": {
                                "description": "AnnotationTitle provides a title for the annotation.",
                                "type": "string"
                            },
                            "type": {
                                "description": "AnnotationType is used to distinguish between annotations designed to support various uses. The types are not enumerated, as these can be specified by the user or creator of the annotations. The definitions and use of annotation types should be documented by their creator.",
                                "type": "string"
                            },
                            "text": {
                                "description": "AnnotationText holds a best language match string containing the text of the annotation.",
                                "$ref": "#/definitions/localisedBestMatchText"
                            },
                            "texts": {
                                "description": "AnnotationText holds language-specific strings containing the texts of the annotation.",
                                "$ref": "#/definitions/localisedText"
                            },
                            "id": {
                                "description": "Non-standard identification of an annotation.",
                                "type": "string"
                            },
                            "links": {
                                "description": "Links field is an array of link objects. Also used to specify the Annotation URL which points to an external resource which may contain or supplement the annotation (using 'self' as relationship). If a specific behavior is desired, an annotation type should be defined which specifies the use of this field more exactly. If appropriate, a collection of links to additional external resources.",
                                "$ref": "#/definitions/links"
                            }
                        }
                    }
                }
            }
        },
        "dimension": {
            "type": "object",
            "required": [
                "id",
                "keyPosition",
                "values"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
                },
                "name": {"$ref": "#/definitions/localisedBestMatchText"},
                "names": {"$ref": "#/definitions/localisedText"},
                "description": {"$ref": "#/definitions/localisedBestMatchText"},
                "descriptions": {"$ref": "#/definitions/localisedText"},
                "roles": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
                    }
                },
                "keyPosition": {
                    "type": "integer",
                    "minimum": 0
                },
                "default": {"type": "string"},
                "links": {"$ref": "#/definitions/links"},
                "annotations": {
                    "type": "array",
                    "items": {
                        "type": "integer",
                        "minimum": 0
                    }
                },
                "values": {"$ref": "#/definitions/values"}
            }
        },
        "attribute": {
            "type": "object",
            "required": [
                "id",
                "relationship",
                "values"
            ],
            "properties": {
                "id": {
                    "type": "string",
                    "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
                },
                "name": {"$ref": "#/definitions/localisedBestMatchText"},
                "names": {"$ref": "#/definitions/localisedText"},
                "description": {"$ref": "#/definitions/localisedBestMatchText"},
                "descriptions": {"$ref": "#/definitions/localisedText"},
                "roles": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
                    }
                },
                "relationship": {
                    "$ref": "#/definitions/AttributeRelationshipType",
                    "description": "AttributeRelationship describes how the value of this attribute varies with the values of other components. These relationships expresses the attachment level of the attribute."
                },
                "default": {"type": "string"},
                "links": {"$ref": "#/definitions/links"},
                "annotations": {
                    "type": "array",
                    "items": {
                        "type": ["integer"],
                        "minimum": 0
                    }
                },
                "values": {"$ref": "#/definitions/attrvalues"}
            }
        },
        "values": {
            "type": "array",
            "items": {
                "type": "object",
                "required": [
                    "id",
                    "name"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9_@$-]+$"
                    },
                    "name": {"$ref": "#/definitions/localisedBestMatchText"},
                    "names": {"$ref": "#/definitions/localisedText"},
                    "description": {"$ref": "#/definitions/localisedBestMatchText"},
                    "descriptions": {"$ref": "#/definitions/localisedText"},
                    "start": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "end": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "parent": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9_@$-]+$"
                    },
                    "order": {
                        "type": "integer",
                        "minimum": 0
                    },
                    "links": {"$ref": "#/definitions/links"},
                    "annotations": {
                        "type": "array",
                        "items": {
                            "type": ["integer"],
                            "minimum": 0
                        }
                    }
                }
            },
            "minItems": 0,
            "uniqueItems": true
        },
        "attrvalues": {
            "type": "array",
            "items": {
                "type": [
                    "null",
                    "object"
                ],
                "properties": {
                    "id": {
                        "type": "string",
                        "pattern": "^[A-Za-z0-9_@$-]+$"
                    },
                    "name": {"$ref": "#/definitions/localisedBestMatchText"},
                    "names": {"$ref": "#/definitions/localisedText"},
                    "description": {"$ref": "#/definitions/localisedBestMatchText"},
                    "descriptions": {"$ref": "#/definitions/localisedText"},
                    "start": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "end": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "links": {"$ref": "#/definitions/links"},
                    "annotations": {
                        "type": "array",
                        "items": {
                            "type": "integer",
                            "minimum": 0
                        }
                    }
                }
            },
            "minItems": 0,
            "uniqueItems": true
        },
        "dataSet": {
            "type": "object",
            "properties": {
                "action": {
                    "type": "string",
                    "enum": [
                        "Information",
                        "Append",
                        "Replace",
                        "Delete"
                    ]
                },
                "reportingBegin": {"type": "string"},
                "reportingEnd": {"type": "string"},
                "validFrom": {
                    "type": "string",
                    "format": "date-time"
                },
                "validTo": {
                    "type": "string",
                    "format": "date-time"
                },
                "publicationYear": {"type": "string"},
                "publicationPeriod": {"type": "string"},
                "annotations": {
                    "type": "array",
                    "items": {
                        "type": "integer",
                        "minimum": 0
                    }
                },
                "attributes": {
                    "type": "array",
                    "items": {
                        "type": ["integer", "null"],
                        "minimum": 0
                    }
                },
                "observations": {
                    "type": "object",
                    "patternProperties": {"^[0-9]+(:[0-9]+)*$": {
                        "type": "array",
                        "items": {"type": ["number", "string", "null"]}
                    }},
                    "additionalProperties": false
                },
                "series": {
                    "type": "object",
                    "patternProperties": {"^[0-9]+(:[0-9]+)*$": {
                        "type": "object",
                        "properties": {
                            "annotations": {
                                "type": "array",
                                "items": {
                                    "type": "integer",
                                    "minimum": 0
                                }
                            },
                            "attributes": {
                                "type": "array",
                                "items": {
                                    "type": ["integer", "null"],
                                    "minimum": 0
                                }
                            },
                            "observations": {
                                "type": "object",
                                "patternProperties": {"^[0-9]+(:[0-9]+)*$": {
                                    "type": "array",
                                    "items": {"type": ["integer", "number", "boolean", "string", "null"]}
                                }},
                                "additionalProperties": false
                            }
                        },
                        "additionalProperties": false
                    }},
                    "additionalProperties": false
                },
                "links": {"$ref": "#/definitions/links"}
            },
            "required": ["links"]
        },
        "AttributeRelationshipType": {
            "description": "AttributeRelationshipType defines the structure for stating the relationship between an attribute and other data structure definition components.",
            "type": "object",
            "properties": {
                "dimensions": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern": "^[A-Za-z][A-Za-z0-9_-]*$",
                        "description": "ID of a local dimension. This is used to reference dimensions in the data structure definition on which the value of this attribute depends. An attribute using this relationship can be either a group, series (or section), or observation level attribute. The attachment level of the attribute will be determined by the data format and which dimensions are referenced."
                    }
                },
                "none": {
                    "type": "object",
                    "description": "This is an empty object and means that value of the attribute will not vary with any of the other data structure components. This will always be treated as a data set level attribute."
                },
                "primaryMeasure": {
                    "type": "string",
                    "pattern": "^[A-Za-z][A-Za-z0-9_-]*$",
                    "description": "ID of a local primary measure. This is used to specify that the value of the attribute is dependent upon the observed value. An attribute with this relationship will always be treated as an observation level attribute."
                }
            },
            "anyOf": [
                {"required": ["dimensions"]},
                {"required": ["none"]},
                {"required": ["primaryMeasure"]}
            ]
        },
        "uri": {
            "description": "Contains the URL to the schema allowing to validate the message. This also allows identifying the version of SDMX-JSON format used in this message. Providing the link to the SDMX-JSON schema is recommended.",
            "type": "string",
            "format": "uri"
        },
        "urn": {
            "type": "string",
            "format": "uri"
        }
    }
}
