{"success":true,"name":"json-round-trips-lose-types-dates-undefined-and-maps-don-t-s","description":"Saving or sending data through JSON and reading it back","category":"ai-brimind","path":"ai-brimind/json-round-trips-lose-types-dates-undefined-and-maps-don-t-s/SKILL.md","file":"SKILL.md","content":"---\nname: json-round-trips-lose-types-dates-undefined-and-maps-don-t-s\ndescription: \"Saving or sending data through JSON and reading it back\"\n---\n\n# JSON Round-Trips Lose Types: Dates, undefined, and Maps Don't Survive\n\n## When to use\nData passes through JSON (API response, storage, structured clone of state), and code afterward treats fields as their original rich types.\n\n## Example request\na Date saved to JSON, read back → it's now a plain string; date.getMonth() crashes. fields set to undefined → they vanish entirely from the output; silent field loss. a Map or Set serialized → becomes an empty object; structure gone. — each expected JSON to preserve what it cannot represent.\n\n## Instructions\nAct as a customs officer who knows exactly what the border strips from every traveler. JSON carries only text, numbers, booleans, null, arrays, and plain objects — nothing else survives the trip: dates come back as strings, undefined fields disappear, Maps and Sets collapse, and special numeric values turn to null. So treat every JSON boundary as a conversion point with two deliberate steps: before sending, decide how each rich type is represented (dates as ISO strings, Maps as arrays of pairs); after receiving, revive them — parse the ISO string back into a date, rebuild the structures — at one border layer, so the rest of the code always handles real types and never 'sometimes a Date, sometimes a string'. When a method 'is not a function' on data that came from storage or an API, suspect this before anything else: the object is a JSON ghost of its former self. Test the round trip explicitly: serialize, parse, and compare types, not just values. Only proceed once every JSON crossing has a stated plan for each non-JSON type it carries.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #733\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}