JSON.stringify()
The JavaScript function that converts a value into a JSON string; JSON.parse() converts the string back.
In more detail
An optional third argument adds indentation for readable output. JSON loses types such as Map, Set and Date and fails on circular references, which the structured clone algorithm handles.
Related terms
- JSON — A simple text format for structured data made of keys, values, lists and nested objects.
- serialization — Turning an in-memory object into bytes, such as JSON text, that can be sent or stored, and parsing it back again.
- structured clone algorithm — The standard JavaScript algorithm for deep-copying values between threads and into storage, which handles Maps, Sets, Dates, typed arrays and circular references.
Taught in
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform
- Client Storage Paradigms: Cookies, Storage Tradeoffs — Frontend Architecture & Web Platform