JSON
Dos builtins, totalmente round-trippables: json_decode(json_encode(x)) reconstruye x.
-- Doc example: JSON encode/decode (pure, round-trippable).
intent: "doc example: JSON"
print(json_encode({"name": "Ada", "tags": ["x", "y"], "n": 3})) -- run shows the JSON
test "encode then decode reconstructs the value"
let data be {"name": "Ada", "tags": ["x", "y"], "n": 3}
let s be json_encode(data)
let back be json_decode(s)
assert_eq(back["name"], "Ada")
assert_eq(back["n"], 3)
assert_eq(length(back["tags"]), 2)
Codificar y decodificar
json_encode(value) -- value → texto JSON
json_decode(text) -- texto JSON → value (object→map, array→list, …)
Qué hace encode con valores especiales
secret→"[redacted]"(seguro — nunca filtra el texto plano).bytes→ un string base64.decimal(1.50d) → un número JSON exacto.nothing→null.
Es la forma idiomática de guardar data estructurada en un valor de texto/Redis:
redis_set("cfg", json_encode({"theme": "dark", "n": 3}))
let cfg be json_decode(redis_get("cfg"))
json_decode da un error claro ante JSON inválido. Ojo: las respuestas del cliente HTTP ya exponen un json of r parseado (ver Cliente HTTP).