An anchor is cloned twice, so an alias is a copy
The /yaml-json page ships its own hand written YAML parser: the template is 76073 bytes over 1857 lines, its script body of 63822 characters is found in that template verbatim once, 100 function declarations settle to 99 unique names, plus 25 DOM ids, and no external library is loaded. This note measures the structural layer: the copy cost of anchors and aliases, the order merge keys land in, the line ending bytes of block scalars, and the scope a document boundary leaves.
A value is cloned once going into the alias table and cloned again when you read it through *base. So b===a is false and b.sub===a.sub is false too: two levels down these are separate objects. Edit k on b and sub.z on b and neither a nor c moves, even though c references *base the same way. Sharing a mutable reference through an alias is not what this page does.
Timing has a detail: the anchor is stored before the tag cast runs. Write a: &s !!str 42 and then b: *s and you get {"a":"42","b":42}. The value under key a was cast into a string, but the uncast number entered the table, so the alias hands back 42.
Aliases never compress either. Point at the same anchor 1, 3 and 10 times and the pretty printed output runs to 130, 256 and 697 characters: each extra reference adds 63 characters, and the result is byte for byte what hand inlining would give.
Fig. 1 The double clone chain and the expansion bill: after the two cuts the alias and the original are unrelated, and the count spreads out linearly at 63 characters a copy.
Merge keys: merged lays the ground, own writes last
The rule for << is to flatten the merged sources first and write this level's own keys after, so on a shared name own survives. The sequence form <<: [*m1, *m2] flattens in reverse: m2 goes down first and m1 lands on top, so the earlier alias wins. A merged value is cloned once more too, so an alias never gives you the original object.
| Written as | Measured output | Why |
|---|---|---|
<<: *base plus an own key of the same name | key order x,y,z, y=9 | merged first, own overwrites |
<<: [*m1, *m2] | x=1, key order holds 3 keys | reverse flattening, earlier alias wins |
two << lines in one mapping | x=2 | pushed in order, later overwrites |
three level chain d: {<<: *a} | one expansion fills 3 keys | the anchor stores a finished clone |
<< pointing at a scalar or an array | keys still print, warning only | an array reports per element |
The verbatim warning for a non mapping target reads "the merge key << does not reference a mapping, skipped"; an array with two elements produces that sentence twice, and it never becomes an error.
Block scalars: six indicators, six newline bills
One input, two content lines, two empty lines, then a key, measured across all six indicators: the literal output is 10, 9, 10, 9, 5 and 9 characters long. On trailing newlines | and > each keep 1, |- and >- keep none, and |+ keeps 3, the empty line count plus the one it adds back; if the input ends right after a |+ block only 2 survive, because the last empty segment is gone once the block is split. The folding indicator > turns the seam between ordinary lines into a space, folds an empty line into 1 newline, and keeps a newline under any line that opens with a space.
Fig. 2 The two block scalar bills: chomping on the left, explicit indentation slicing on the right.
The indicators and the errors have their own wording: |2 slices at the parent level plus 2 and keeps extra indentation verbatim; |1 leaves 1 leading space on every line; |0 or |x answers that only the digits 1-9 and the modifiers - and + may follow a block scalar indicator; |9 with too little indentation reports the line demanding at least 9 spaces, a message 44 characters long and 108 bytes in UTF-8; a disagreeing automatic indicator says the block is indented 1 space below its first content line. An empty k: | followed by a sibling key resolves to an empty string.
Anchor scope: a table rebuilt per document
The alias table does not outlive a document boundary: it is rebuilt each time a document begins, and two parse calls share no state either. A self reference therefore cannot loop forever, and writing y: *a inside the block that a: &a opens reports an undefined anchor on line 3, in the flow and sequence forms as well, because an anchor is stored only after its whole value has parsed. Reaching across a boundary fails the same way with the source line number quoted, and a name such as &x redefined in the next document keeps the two sets of references apart.
The multi document switch changes the wrapper, not the accounting. Off, three documents raise one message saying the input contains 3 documents, and the output is an empty string; that message sits on line 0 with no line or column metadata. On, you get an array of 3 elements. If one document breaks on its own, as the reference above does, the interface shows its alias error instead of a count error. An empty string and a comment only input each count as 1 document whose value is null, and a same line opening such as --- k: v becomes an indented line and parses as usual.
Hash, colon, and the two boolean tiers
A # opens a comment only when a line start or whitespace leads it: http://x#y survives whole, b#c is glued and is not a comment, and 1#c stays a string although it opens with a digit. Inside quotes every # is content. A colon counts as a separator only when whitespace or the line end follows, so the key in a:b: c is a:b. Strict and loose tiers flip 3 key types across a sample of yes/on/Off/Y/n/true/null, and strict still accepts True/TRUE/false/FALSE, so the page claim that booleans are only true and false is partly right.
The whole interface chain ran against a DOM stub: the built-in sample YAML prints 1166 characters, and the statistics line reads, word for word, 45 nodes, maximum depth 7, 1 document, 34 keys and 10 array items. The error panel carries five parts, title, coordinates, body, source pointer and suggestion, and the column number is that line's indentation plus 1, so the undefined alias on the second line renders as line 2, column 3. Every change on the four switches writes to localStorage and re-runs the parse. Real browser painting and debounce merging were not exercised in this batch, so they stay marked untested.
Common questions
Q: If I change a value reached through an alias, does the original change too?
No. It is cloned going in and cloned coming out, so an alias and the original share no objects even two levels deep. Editing the copy reaches neither the original nor the other aliases.
Q: Between a merge key and an own key of the same name, which wins?
own wins, because merged lays the ground first and own writes last. Inside the sequence form <<: [*m1, *m2] the flattening runs in reverse, so on a clash the alias written earlier takes the name.
Q: Can a document reuse an anchor from the document before it?
It cannot. The alias table is rebuilt per document, so a cross document reference only comes back as an undefined anchor. Redefine the name inside the document that needs it.
Every figure above was measured on the parser inside the YAML JSON converter page. When you are unsure which JSON output tier you are on, compare the pretty and minified byte counts on the JSON formatter page. The scalar type line, the boolean word list and how numbers are recognised, was measured in an earlier note, YAML scalar type rewrite, and that table is not rebuilt here.