CompactData is a data serialisation format with the goal of describing objects in as few characters as possible. CompactData has particular application in DNS TXT records because:
-
it is character-efficient
-
it is easily minified
-
keys and values do not need to be "quoted" – avoiding DNS storage issues
Until now, developers have rolled their own methods of storing data in DNS TXT records, presenting significant limitations and a barrier to entry for those looking to store data in DNS. CompactData aims to standardise data storage in DNS TXT.
-
Whitespace means space (
0x20) or tab (0x09). -
Newline means
LF(<0x0A) orCRLF(0x0D0A). -
CompactData ignores all leading and trailing whitespace.
-
CompactData files must be valid UTF-8 encoded Unicode documents.
Values are described precisely below:
A map begins with left parenthesis ( and ends with right parenthesis ), it contains zero or more pairs separated by a semi-colon (;).
(
a=1;
b=2;
c=3
)<zoom id="this"> <z1>This is a brief description of a thing</z1> <z2>This is a more detailed description of the thing and explains a few different components involved</z2> <z3>This is much more detailed description of the thing starting with the founding principles and then working through all of the individual components and how they fit together</z3> <z4>This is much more detailed description of the thing starting with the founding principles and then working through all of the individual components and how they fit together. We really get into the nuts and bolts of it here</z4> <z5>This is much more detailed description of the thing starting with the founding principles and then working through all of the individual components and how they fit together. We really get into the nuts and bolts of it here and the description more or less starts with explaining what the universe is and what atoms are, literally starting from the very start.</z5> </zoom>
Arrays in CompactData will be familiar to most – beginning with a left square bracket [ and ending with a right square bracket ] containing zero or more values separated by a semi-colon ;. Array items can be of any data type and data types can be mixed.
[
1;
2;
3
]Pairs are the primary building block of CompactData and consist of a value assigned to a key. They can be used in a number of ways to aid character efficiency. Orphan pairs (not within a map) are allowed for character efficiency and are converted into a map when parsed.
When assigning a map to a key, we can omit = since the left parenthesis separates the key from the map contents:
(
a(
b=1
)
)When assigning an array to a key, we can omit = since the left square bracket separates the key from the array contents:
(
a[
1;
2
]
)An orphan pair is one that is expressed outside of a map, either at the top level of an object or as an array value.
Pairs can be expressed outside of a map at the top level and they are automatically considered pairs in the same map:
a=1;
b=2;
c=3Numbers in CompactData are the same as numbers in JSON view RFC.
Strings in CompactData are the same as strings in JSON view RFC, with the exception that they can also be unquoted and .graved
True is represented using true and false is represented using false – in both cases, the same as JSON.
CompactData infers the type of a value, to set a number to a string it can be quoted. For example:
(
force_number_as_string="1"
)Values can be quoted using double quotes (") or DNS-friendly graves ( ` ), for example:
(
force_number_as_string="1";
force_another_number_as_string=`2`
)Like JSON, the backslash (\) can be used to escape characters. In addition, the DNS-friendly tilde (\~) can also be used as an escape character. For character efficiency, it’s usually better to quote values that include more than one reserved character. For example:
(
include_one_reserved_char = we won :\);
include_many_reserved_chars = "this (that [the other]"
)In CompactData tilde (\~) is equivalent to backslash (\). Backslash can be used to escape tilde and tilde can be used to escape backslash. Tilde can be used to escape tilde. Backslash can be used to escape backslash.
CompactData is not limited to ASCII characters. but some storage media are (e.g. DNS TXT records). Non-ASCII characters can be expressed in ASCII CompactData in two ways:
For character efficiency, you should use a quoted or graved string if a value includes two or more reserved characters, otherwise use an escape character (\ or \~) for a single reserved character. The following characters have special meaning in CompactData:
-
Brackets: The left bracket
(indicates the start of a map, the right bracket)indicates the end. -
Square Brackets: The left square bracket
[indicates the start of an array, the right square bracket]indicates the end. -
Semi-colon
;is used in a map to separate pairs and used in an array to separate items. -
Grave accents and double quotes (
`and"respectively) are used for quoting values -
Backslash and tilde (
\and~respectively) are escape characters and can be used before any reserved character to escape its reserved use. To use a backlash or tilde in a CompactData object, simply use two:\\,~~,\~or~\.