Skip to Content
DocumentationFormat Escaping

Format Escaping

Codables use format like { $$Set: [1, 2, 3] } to encode various types.

It is unlikely, but possible, that some data looking exactly like this will be passed to be encoded.

Automatic Escaping

When your data contains keys that conflict with Codables’ internal format (like $$Set, $$Map, etc.), they are automatically escaped into object like { "~$$Set": [1, 2, 3] }.

Later on, when you decode, it will be unescaped back to { $$Set: [1, 2, 3] }, but will not be treated as a custom type.

import { encode, decode } from "codables"; // This data conflicts with Set encoding format const conflictingData = { $$Set: [1, 2, 3], // Conflicts with Set serialization $$Map: [["key", "value"]], // Conflicts with Map serialization $$Date: "not-a-date" // Conflicts with Date serialization }; const encoded = encode(conflictingData); // { "~$$Set": [1, 2, 3], "~$$Map": [["key", "value"]], "~$$Date": "not-a-date" } const decoded = decode(encoded); // decoded.$$Set === [1, 2, 3] // decoded.$$Map === [["key", "value"]] // decoded.$$Date === "not-a-date"
Last updated on