Objects are the last kind to serialize - key-value members joined by commas, with each key written as a quoted string. Today you complete the compact serializer.
Serialize an object value as a compact list of quoted-key, value members in stored order.
An object serializes like an array, with one twist per member: each member is a
quoted key, a colon, and the serialized value. Reuse the string serializer from two
lessons ago for the key so that keys needing escapes are handled correctly. Members
are separated by commas, with no spaces around the colon or the comma in compact
form, and the empty object is {}.
Crucially, emit members in their stored order - the order the parser preserved -
rather than sorting or randomizing them. That makes serialization deterministic and,
for a document that was parsed from canonical text, an exact inverse of parsing.
With objects done, Serialize covers all six value kinds, and every value tree can
now be written back to text. The next lesson proves it forms a clean round-trip.
// object case of Serialize:// '{' + join(serializeString(m.Key)+":"+Serialize(m.Value), ",") + '}'// reuse the string escaper for the key; no spaces around ':' or ','// iterate members in their stored order