This document describes how Refract can be serialised into other forms such as JSON along with including all serialisation guidelines.
A Refract element MUST be serialised fully as the following data structure as a JSON object:
- element (required, string)
- meta (optional, object)
- attributes (optional, object)
- content (optional, enum)
- Element
- array[Element]
- string
- boolean
- number
- null
- Key Value Pair
The element name MUST always be present and it MUST contain the name of the Refract element as a string.
Meta will contain all the meta properties, this SHOULD NOT be present in the serialisation if there are no meta properties. When there are any meta properties set, the meta SHOULD be serialised. Meta SHOULD contain a JSON object which matches the keys and values described in the Refract specification. All values in the object must be Refracted elements.
Attributes will contain all the attributes of an element, this SHOULD NOT be present in the serialisation if there are no attributes. When there are any attributes set, the attributes SHOULD be serialised. Attributes SHOULD contain a JSON object which contains the attributes in the Refract specification. All attribute values in the JSON object must be Refracted elements.
The content of an element MUST be one of the following types:
- Element - Another JSON serialised element
- array[Element] - An array of JSON serialised elements
- string - A JSON string
- boolean - A JSON boolean value (true/false)
- number - A JSON number
- null - A JSON null (
null
) - Key Value Pair (object) - A JSON object representing a key-value pair
- key (required, Element) - A required key
- value (Element) - An optional value
An element is not required to have content.
{
"element": "string"
}
{
"element": "string",
"content": "Doe"
}
{
"element": "string",
"meta": {
"title": {
"element": "string",
"content": "Name"
}
},
"content": "Doe"
}
{
"element": "string",
"meta": {
"title": {
"element": "string",
"content": "Person"
}
},
"attributes": {
"address": {
"element": "string",
"content": "49 Featherstone Street, London, EC1Y 8SY"
}
},
"content": "Doe"
}
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "Name"
},
"value": {
"element": "string",
"content": "Doe"
}
}
}
{
"element": "dns-resource",
"content": [
{
"element": "dns-record",
"attributes": {
"ttl": {
"element": "number",
"content": 86400
}
},
"content": "_sip._tcp.example.com"
}
]
}