Ord JSON mapping
Version 0.7.0-draft, 2026-11-22. A companion spec to Ord specification, of the same version. The Spec's conventions (S1 to S6) and versioning (S10) apply here, and rule IDs that start with C, L, D or T refer to the Spec and the Test format.
1. Scope
- J17. This spec maps JSON to the Core data model (Spec, section 1) and back. It keeps the hierarchy: what is under a node in Ord is under its label in JSON, and simple Ord is simple JSON. JSON → Ord → JSON gives the same JSON value; Ord → JSON → Ord keeps what JSON has a place for, and section 6 lists what it doesn't.
- J1a. The mapping is syntactic. It doesn't read label syntax (Spec Part 2), resolve references or check reserved names (Semantics M92), so a reference is the text written, e.g.
client:: acmegives"client": "acme", and a key that starts with_is a key like any other, both ways:_id:: acmegives"_id": "acme", and back. It reads only these: numbers (L22) and booleans (L27) among a field's items, which JSON has types for;[]and{}, an empty array and object (J4, J7); index keys (J20); the root field_json(J19); the JSON member_ord(J22); and the text tests of J23. - J18. A JSON mapper reads and writes JSON as this spec says, and passes the tests with the
from-jsonandto-jsonoptions (T4).
2. Shapes
These shapes are the same in both directions.
- J21. A node's node array is what is under the node, as a JSON array: first, when the node has fields, one object of them, its fields object, each field a member (J5, J7a); then its child nodes, in order (J3, J4). A node with a label and children is an object with one member, its label, whose value is its node array (J3):
{"Kickoff": [{"date": "2026-12-01"}, "Book room"]}isKickoffwithdate:: 2026-12-01andBook roomunder it. The root is its node array, unless it has only fields (J2). - J20. An index node is a node, the root, a node with a label or a field's anonymous node (C13), whose children are only field lines, at least one, with unquoted keys
0,1,2and so on, in file order: each key is its line's position, in digits without a leading zero. It is the JSON array of its fields' values (J5), in order, in place of its node array or object. So the root0:: a, then1::withb:: 2under it, is["a", {"b": 2}], andAcmewith0:: xand1:: 5under it is{"Acme": ["x", 5]}. A quoted key ("0":: a) or a key out of order makes an ordinary field. Readers write an array as index fields where no other rule maps it (J10, J11, J15), and quote the keys of an object that would read as an index node:{"0": "a"}gives"0":: a. - J19. A root whose only line is a field line with the unquoted key
_jsonis the JSON value of that field (J5):_json:: 5is5,_json:: "6"is"6",_json::isnulland_json:: []is[]. A_jsonfield anywhere else, or on a root with other lines, is the warningJ19.1, and is an ordinary field. A root object whose only member is_jsonis written with the key quoted,"_json":: 5, and the quoted key is an ordinary field. - J22. The member
_ord, with the value"fields"or"node", marks an object that J26 reads with its other members:"fields"says they are fields, and"node"that the object is a node. It is a marker only in an object that, without it, has one member, whose value is a non-empty array, where J26 reads one; it is never a field. Anywhere else, or with another value,_ordis an ordinary member. Writers write it only where J26 would read the object as the other one (J24). - J23. Two text tests guess, where the structure doesn't say (J26), whether text is a field's or a node's:
- A key looks like a key when it starts with a lowercase letter (Unicode
Ll) or_and has no spaces or tabs:attendees,due_date,_tags.Planning,Book roomandQ4don't. - A string is prose when it has three or more words (runs of characters other than spaces and tabs), or ends with
.,!or?:Welcome and introductions,Went well..Anna Smith,acme.comand9.5aren't.
- A key looks like a key when it starts with a lowercase letter (Unicode
3. Writing JSON
J2. The root becomes:
- the value of its
_jsonfield, when that is its only line (J19) - an array, when it is an index node (J20)
- an object of its fields, when it has only fields (J5, J7a)
{}, when it has no lines- otherwise its node array (J21).
- the value of its
J3. A node with children becomes an object with one member: the key is its label, as text, and the value its node array (J21), or, for an index node, its array (J20). An empty label is the key
"".J4. A node without children becomes its label as a string, whatever it reads as: labels are text, so a line
2026is"2026". The exceptions are an unquoted{}or[], an empty object or array. An empty label,::or"", is"".J5. A field's JSON value is:
null, if it has no items and isn't a list- the item itself, if it has one item and isn't a list
- an array of its items, if it has several, or is a list (C16):
a;gives["a"]and;gives[].
Its items, in order (C38), are its text items (J6, J7), its nodes (J3, J4) and its anonymous node, which is an object of its fields, or an array when it is an index node (J20).
J6. A text item becomes a string, unless J7 says otherwise.
J7. An unquoted text item that is a number (L22) becomes a JSON number, written as it is written in Ord, and one that is a boolean (L27)
trueorfalse; an unquoted[]becomes an empty array and{}an empty object:n:: 1.50; 1e3; TRUE; []gives"n": [1.50, 1e3, true, []]. A number keeps all its digits, whatever a JSON reader can hold. Every other value is a string: quoted text ("3"), other value forms such as dates, links and formulas as written.J7a. Fields with the same key on one node become one member. Their items are concatenated in file order, and the result is always an array:
tag:: aandtag:: bgive"tag": ["a", "b"]. So a field line per record is an array of objects:rows::witha:: 1under it, thenrows::witha:: 3under it, gives"rows": [{"a": 1}, {"a": 3}].J24. Where J26 would read an object of the JSON as a node and it is fields, the writer adds
"_ord": "fields"to it, and where it would read fields and it is a node,"_ord": "node"(J22). SoNoteswithtodounder it, andBook roomunder that, gives{"Notes": [{"todo": ["Book room"], "_ord": "node"}]}, sincetodolooks like a key.J25. An Ord field
_ordon an object that J22 would read as a marker gives a warning. It is written as the member it is.
Acme
→Call Anna
→Workshop
→→hours:: 6
→Planning
→→Book room
→→Send agenda
.
[
{
"Acme": [
"Call Anna",
{ "Workshop": [{ "hours": 6 }] },
{ "Planning": ["Book room", "Send agenda"] }
]
}
]
client:: Acme
Kickoff
→attendees:: Anna; Erik
→Book room
Notes
→todo
→→Book room
Plan
→Steps:: a;
→Call
Retro
→date:: 2026-12-01
→Planning
→→Milk
.
[
{ "client": "Acme" },
{ "Kickoff": [{ "attendees": ["Anna", "Erik"] }, "Book room"] },
{ "Notes": [{ "todo": ["Book room"], "_ord": "node" }] },
{ "Plan": [{ "Steps": ["a"], "_ord": "fields" }, "Call"] },
{ "Retro": [{ "date": "2026-12-01" }, { "Planning": ["Milk"] }] }
]
Call Anna
2026
{}
[]
"{}"
::
""
.
["Call Anna", "2026", {}, [], "{}", "", ""]
a::
b:: ""
c:: x;
d:: []
e:: {}
f:: ;
g:: "{}"
n:: 1.50; -2; TRUE; 1e3
s:: "3"
dt:: 2026-10-15
v:: 007
tag:: a
tag:: b
contact::
→primary:: anna
people::
→Anna
→Erik
k:: x
→Anna
→primary:: anna
client:: [[Acme Corp]]
_id:: acme
.
{
"a": null,
"b": "",
"c": ["x"],
"d": [],
"e": {},
"f": [],
"g": "{}",
"n": [1.50, -2, true, 1e3],
"s": "3",
"dt": "2026-10-15",
"v": "007",
"tag": ["a", "b"],
"contact": { "primary": "anna" },
"people": ["Anna", "Erik"],
"k": ["x", "Anna", { "primary": "anna" }],
"client": "[[Acme Corp]]",
"_id": "acme"
}
rows:: x
→a:: 1
→n:: 2
rows::
→a:: 3
rows:: y
.
{
"rows": ["x", { "a": 1, "n": 2 }, { "a": 3 }, "y"]
}
rows::
→0::
→→a:: 1
→1:: x; y
→2::
same::
→"0":: a
→1:: b
Acme
→0:: x
→1:: 5
.
[
{
"rows": [{ "a": 1 }, ["x", "y"], null],
"same": { "0": "a", "1": "b" }
},
{ "Acme": ["x", 5] }
]
0:: a
1::
→0:: b
→1:: []
.
["a", ["b", []]]
_json:: "6"
.
"6"
_json:: 1e3
.
1e3
"_json":: 5
.
{ "_json": 5 }
4. Reading JSON
JSON is read by writing it as Ord, as these rules say, and reading the result (Spec, Part 1).
J15. The root becomes:
- for an object, its members as the root's fields (J8), and nothing for
{} - for an array, the root's lines as J11 reads a node array, except that an array whose only element J11 would read as the fields becomes index fields (J20), since fields alone are an object (J2)
- for a scalar or
[], the field_jsonwith the value, as J9 and J10 write a field's (J19):5gives_json:: 5and[]gives_json:: [].
- for an object, its members as the root's fields (J8), and nothing for
J8. An object read as fields becomes a field line per member, with the member's key (J12), in order, and the value as J9 and J10 say; a marker
_ord(J22) is left out. An object is read as fields as the root (J15), as the first element of a node array (J11, J26), as a field's value (J9, J26) and as an element of a field's array (J10, J26).J9. A field's value:
- A string becomes the field's item, quoted (C26) when it is a number (L22), a boolean (L27),
[]or{}as written, so that it stays text:"6"givescode:: "6". - A number becomes its text as written in the JSON, and a boolean
trueorfalse, so each reads back as its value form:6,9.50,1e21andtruegivehours:: 6,9.50,1e21andtrue. nullbecomes no items,key::.{}becomes{}. Any other object becomes the field's field children (J8), or, when J26 reads it as a node, its one node item (J11).- An array follows J10.
- A string becomes the field's item, quoted (C26) when it is a number (L22), a boolean (L27),
J10. A field's array:
[]becomeskey:: [].- An array that holds
null, or an array that isn't empty, becomes index fields (J20), under the field as its field children, each element an index field's value (J9, J10):"e": [null, "y"]givese::with0::and1:: yunder it, and"m": [["a", "b"], ["c"]]givesm::with0:: a; band1:: c;under it. - Any other array becomes the field's items, in order, on one field line or more (J7a). Strings that aren't prose (J23), numbers, booleans,
[]and{}are its inline items (J9); prose strings, and objects that J26 reads as nodes, are node lines under it (J11), so"agenda": ["Welcome and introductions", "Budget"]givesagenda::with the two lines under it; and an object read as fields (J26) is its field children (J8). A field line holds them in the order C38 allows: inline items, then node lines, of which a string after a node line is one too, then at most one object as its field children. A new field line with the same key starts where the next element doesn't fit: so a field line per record (J7a), and an inline item after a node line on a field line of its own. - An array on one field line with one item is a list (C16), with a
;after its items:key:: a;, andkey:: ;with the object's fields, or the node line, under it for one object or prose string.
J11. A node array, a root array (J15) or the array under a label (J3), becomes the node's lines (J21) when it isn't empty, its first element is a string, an object,
[]or{}, and every other element is a string,[],{}or a node object, an object with one member whose value is a non-empty array. Then:- A first element that is an object other than
{}becomes the node's fields (J8), unless it is a node object that J26 reads as a node. - A string becomes a node line, its label the string, quoted (C26) when it is
[]or{}as written, and""when it is empty (C42); a line is never read as a number or boolean, so"6"gives6. []and{}become the lines[]and{}.- A node object becomes a node line with the key as its label, quoted as a string is, and the lines under it that this rule reads from its array.
Any other array, one with a number, a boolean,
null, an array that isn't empty, or an object other than a node object after the first element, becomes index fields (J20), each element an index field's value (J9, J10):["Call Anna", {"a": 1}]gives0:: Call Anna, then1::witha:: 1under it.- A first element that is an object other than
J26. A node object (J11) can also be fields where it is the first element of a node array (J11), a field's value (J9) or an element of a field's array (J10):
{"attendees": ["Anna", "Erik"]}is the fieldattendees:: Anna; Erikor a nodeattendeeswith two lines under it. It is read, in turn:- as its marker says (J22)
- as fields when J11 wouldn't read its array as a node's lines and the array holds no
nulland no array that isn't empty, so that only fields need no index fields:{"scores": [1, 2]}is fields - as fields when its key looks like a key and none of the strings in its array is prose (J23), and otherwise as a node.
So
{"attendees": ["Anna Smith", "Erik"]}is fields, and{"Planning": ["Milk", "Eggs"]}and{"notes": ["Ask about the budget.", "Check"]}are nodes. Elsewhere, a node object is a node (J11) or fields (J15).J12. Text is quoted according to C26: keys, labels and items.
J28. An object with the same key twice, which JSON allows and many JSON readers reduce to the last, keeps both, as a field line each, in order, and gives a warning:
{"a": 1, "a": 2}givesa:: 1anda:: 2, which write back as"a": [1, 2](J7a).
{
"client": "Acme Corp",
"hours": 6,
"rate": 9.50,
"billable": true,
"code": "6",
"flag": "true",
"big": 1e21,
"none": null,
"tags": ["design", "review"],
"one": ["x"],
"address": { "street": "Main 1", "city": "Lund" }
}
.
root
field "client"
"Acme Corp"
field "hours"
"6"
field "rate"
"9.50"
field "billable"
"true"
field "code"
quoted "6"
field "flag"
quoted "true"
field "big"
"1e21"
field "none"
field "tags"
"design"
"review"
field "one" list
"x"
field "address"
node
field "street"
"Main 1"
field "city"
"Lund"
[
{ "client": "Acme" },
{ "Kickoff": [{ "date": "2026-12-01", "room": "B2" }, "Book room", "Send agenda"] },
{ "Planning": ["Book room", { "Workshop": [{ "hours": 6 }] }] },
"Follow up"
]
.
root
field "client"
"Acme"
node "Kickoff"
field "date"
"2026-12-01"
field "room"
"B2"
node "Book room"
node "Send agenda"
node "Planning"
node "Book room"
node "Workshop"
field "hours"
"6"
node "Follow up"
[
{ "Kickoff": [{ "attendees": ["Anna Smith", "Erik"] }, "Book room"] },
{ "Acme": [{ "Planning": ["Milk", "Eggs"] }] },
{ "Notes": [{ "todo": ["Book room", "Send agenda"], "_ord": "node" }] },
{ "Q4": [{ "scores": [1, 2] }] },
{ "Retro": [{ "tags": ["Went well.", "x"] }] },
{ "Plan": [{ "Steps": ["a"], "_ord": "fields" }] }
]
.
root
node "Kickoff"
field "attendees"
"Anna Smith"
"Erik"
node "Book room"
node "Acme"
node "Planning"
node "Milk"
node "Eggs"
node "Notes"
node "todo"
node "Book room"
node "Send agenda"
node "Q4"
field "scores"
"1"
"2"
node "Retro"
node "tags"
node "Went well."
node "x"
node "Plan"
field "Steps" list
"a"
[{ "Planning": [] }, "", {}, [], "{}", "6"]
.
root
field "Planning"
"[]"
node quoted ""
node "{}"
node "[]"
node quoted "{}"
node "6"
{
"lines": [
{ "name": "Workshop", "hours": 6 },
{ "name": "Spec review", "hours": 9.5 }
],
"rows": ["x", { "a": 1 }, { "a": 3 }],
"single": [{ "a": 1 }]
}
.
root
field "lines"
node
field "name"
"Workshop"
field "hours"
"6"
field "lines"
node
field "name"
"Spec review"
field "hours"
"9.5"
field "rows"
"x"
node
field "a"
"1"
field "rows"
node
field "a"
"3"
field "single" list
node
field "a"
"1"
{
"tags": ["design", "review"],
"agenda": ["Welcome and introductions", "Budget"],
"notes": ["Ask about the budget.", "Check the room", 5],
"note": ["Ask about the budget."]
}
.
root
field "tags"
"design"
"review"
field "agenda"
node "Welcome and introductions"
node "Budget"
field "notes"
node "Ask about the budget."
node "Check the room"
field "notes"
"5"
field "note" list
node "Ask about the budget."
{
"matrix": [["a", "b"], ["c"]],
"mixed": ["x", [], "y"],
"e": [null, "y"]
}
.
root
field "matrix"
node
field "0"
"a"
"b"
field "1" list
"c"
field "mixed"
"x"
"[]"
"y"
field "e"
node
field "0"
field "1"
"y"
[
{ "name": "Workshop", "hours": 6 },
{ "name": "Spec review" }
]
.
root
field "0"
node
field "name"
"Workshop"
field "hours"
"6"
field "1"
node
field "name"
"Spec review"
["Call Anna", { "Acme": [{ "a": 1 }, { "a": 2 }] }]
.
root
node "Call Anna"
node "Acme"
field "0"
node
field "a"
"1"
field "1"
node
field "a"
"2"
[1, true, null]
.
root
field "0"
"1"
field "1"
"true"
field "2"
[{ "a": 1 }]
.
root
field "0"
node
field "a"
"1"
5
.
root
field "_json"
"5"
"6"
.
root
field "_json"
quoted "6"
null
.
root
field "_json"
[]
.
root
field "_json"
"[]"
{"_id": "acme", "a": 1, "a": 2}
.
root
field "_id"
"acme"
field "a"
"1"
field "a"
"2"
! J28 1:25
5. Shapes compared
How each common Ord shape looks in JSON, as a summary of the rules above:
| Ord | JSON |
|---|---|
| fields on the root | {"client": "Acme", "hours": 6} |
| lines on the root | ["Call Anna", "Book room"] |
| a node with fields | {"Workshop": [{"hours": 6}]} |
| a node with lines | {"Planning": ["Book room", "Send agenda"]} |
| a node with fields and lines | {"Kickoff": [{"date": "2026-12-01"}, "Book room"]} |
| fields and lines on the root | [{"client": "Acme"}, "Follow up"] |
tags:: a; b, or a and b as lines under tags:: |
"tags": ["a", "b"] |
address:: with city:: Lund under it |
"address": {"city": "Lund"} |
| a field line per record | "rows": [{"a": 1}, {"a": 3}] |
index fields 0::, 1:: |
["a", {"b": 2}] |
_json:: 5 |
5 |
6. Known gaps
JSON read as Ord and written back is the same JSON value, every number as written. What Ord → JSON → Ord loses is Ord's layout, which JSON has no place for:
- The order between a node's fields and its child nodes. They come back fields first.
- How a field's items were written, inline or as lines (J10 chooses), and in how many field lines with the same key (J7a).
- Index fields whose array J11 reads as a node's lines come back as lines:
0:: aand1:: bgive["a", "b"], which is the linesaandb. - A quoted label comes back unquoted, unless it must be quoted: the line
"6"gives"6", which is the line6, and::comes back as"".TRUEcomes backtrue. - An Ord field
_ordthat would read as a marker comes back as one (J25). - An unquoted
[]or{}, as a label or an item, is an empty array or object (J4, J7), even where it was written as text. - Keys that look like index keys come back quoted (J20).
7. Diagnostics
Codes and severities work as in the Spec (C35 to C37). Positions are in the input: the JSON text when reading JSON, the Ord file when writing JSON. Lines and columns are counted as in the Spec (D9), and a JSON key's position is its opening ".
| Code | Severity | Given when | Position |
|---|---|---|---|
J19.1 |
warning | A field _json isn't the root's only line |
the field's key |
J25 |
warning | An Ord field _ord would read back as a marker (J22) |
the field's key |
J28 |
warning | A JSON object has the same key twice | the later key |
Source: JSON_mapping.md in ordlang/ord, licensed under CC BY 4.0.