Serialize vs Deserialize JSON: What Each Step Changes and When the Round Trip Holds
How JSON serialization and deserialization differ, what changes between in-memory data and JSON text, where meaning gets lost, and when plain text is the better choice.
Serialization and deserialization are two halves of one round trip. Serializing turns data that lives in a program's memory, such as objects, arrays, numbers and strings, into JSON text that can be stored or sent. Deserializing reads that JSON text and rebuilds data structures a program can work with. This review explains what each step actually changes, where the round trip loses or alters meaning, and how to judge whether JSON fits a given use.
The short answer
| Aspect | Serialize | Deserialize |
| Direction | In-memory data to JSON text | JSON text to in-memory data |
| JavaScript built-in | JSON.stringify | JSON.parse |
| Python standard library | json.dumps / json.dump | json.loads / json.load |
| Typical failure | Value has no JSON equivalent (dropped, converted or rejected) | Text is not valid JSON, or valid JSON has an unexpected shape |
| Main risk | Silent loss of type or precision | Trusting untrusted input without validating it |
Is JSON serialization suitable for your use?
JSON is a good fit when you need to move structured data between programs, languages or storage layers, and the data is made of plain values: strings, numbers, booleans, null, arrays and key-value objects. Its main benefit is that almost every language can read and write it, and the result is text a person can inspect.
The decisive tradeoff is that JSON has a small, fixed set of types. Anything richer, such as dates, very large integers, binary data, sets, class instances or functions, has to be converted into one of those types on the way out and reconstructed by convention on the way back. The format itself does not record what the original type was, so both sides must agree on that convention.
Plain text is preferable when there is no structure to preserve: a single message, a log line meant only for people, or content a reader will copy into an email or document. Wrapping such content in JSON adds quotes, escapes and braces without adding meaning. Similarly, if the only consumer is a human reading on screen, a formatted table or prose summary usually serves better than raw JSON.
What serialization actually changes
Serialization changes the stored representation, not just how it looks. The output is a new string of characters that follows the JSON grammar defined in RFC 8259 and ECMA-404. Along the way, values without a JSON equivalent are transformed according to the serializer's rules, and those rules differ between languages and libraries.
In JavaScript, JSON.stringify follows documented rules that commonly surprise people:
- Properties whose value is undefined, a function or a symbol are omitted from objects; inside arrays they become null.
- NaN, Infinity and -Infinity become null.
- Date objects become ISO 8601 strings because Date defines a toJSON method.
- BigInt values cause a TypeError unless you supply your own conversion.
- Map and Set instances serialize as empty objects because their contents are not stored as enumerable properties.
const order = {
id: 42,
placed: new Date("2026-01-15T10:00:00Z"),
note: undefined,
total: 19.5
};
JSON.stringify(order);
// '{"id":42,"placed":"2026-01-15T10:00:00.000Z","total":19.5}'
The note property is gone, and placed is now a string. Nothing in the output says it was ever a date.
Python's json module has different defaults. Tuples serialize as arrays. Dictionary keys that are integers, floats, booleans or None are converted to strings, so a key of 1 comes back as "1". By default json.dumps writes NaN and Infinity as bare tokens, which most JSON parsers outside Python reject; passing allow_nan=False makes it raise an error instead. Objects such as datetime or custom classes raise a TypeError unless you provide a default function or a custom encoder.
What deserialization actually changes
Deserialization parses text and builds generic structures: in JavaScript, plain objects, arrays and primitives; in Python, dicts, lists, strings, ints, floats, booleans and None. It does not restore the original types unless you tell it how. The date string from the example above stays a string after JSON.parse. JavaScript's parse accepts a reviver function, and Python's loads accepts object_hook and related parameters, which let you convert values back into richer types as they are read.
const restored = JSON.parse(text, (key, value) =>
key === "placed" ? new Date(value) : value
);
Two parsing details matter for meaning. First, number precision: JavaScript parses all JSON numbers as double-precision floats, so integers larger than 2^53 − 1 can silently change value. IDs from databases that use 64-bit integers are often sent as strings for this reason. Python parses JSON integers as arbitrary-precision ints, so the same text can yield different values in different languages. Second, duplicate keys: RFC 8259 says object member names should be unique and that behavior with duplicates is unpredictable. JavaScript's JSON.parse and Python's json.loads both keep the last value, but other parsers may differ.
Does the round trip preserve meaning?
For plain data that already uses only JSON types, serializing and then deserializing returns equivalent values, though not identical object instances. For anything else, the round trip is lossy unless both sides apply matching conversions. A practical test is to serialize representative data, parse it back, and compare the result field by field with the original, paying particular attention to dates, large numbers, missing optional fields and non-string keys.
Formatting versus content: pretty-printing and minifying
JSON allows insignificant whitespace between tokens. Pretty-printing adds line breaks and indentation; minifying removes them. Both change the stored text but not the parsed data, so a pretty-printed file and its minified version deserialize to the same values. This differs from a viewer that only displays JSON with indentation and syntax colors without rewriting the file: that is presentation, and the underlying text is unchanged.
JSON.stringify(order, null, 2);
// {
// "id": 42,
// "placed": "2026-01-15T10:00:00.000Z",
// "total": 19.5
// }
Key order is a related point. JSON objects are defined as unordered, so a tool that sorts keys produces text that differs byte for byte but should mean the same thing. Code that compares JSON as raw strings, for example to detect changes or compute signatures, can treat these as different even though the data is equal.
Unicode, escaping and emoji
JSON strings can hold any Unicode text, either as literal characters or as \u escape sequences. The two forms are different stored text but parse to the same string. Python's json.dumps escapes all non-ASCII characters by default; setting ensure_ascii=False writes them literally. JavaScript's JSON.stringify writes most non-ASCII characters literally.
Characters outside the Basic Multilingual Plane, including most emoji, are written as a UTF-16 surrogate pair when escaped. The grinning face emoji, U+1F600, becomes \ud83d\ude00. An emoji built from several code points, such as one with a skin-tone modifier or a sequence joined with zero-width joiners, is serialized as each of its code points in order. Combining marks are preserved as separate code points too: an e followed by a combining acute accent stays as two code points (e\u0301) and is not merged into the single precomposed é. Neither serializing nor parsing normalizes Unicode, so two strings that look identical can still compare as unequal after a round trip if they started in different normalization forms.
Will serialized JSON stay usable after copying or sharing?
Because JSON is plain text, copying it between code editors, terminals and plain-text fields normally keeps it intact. Problems tend to come from destinations that treat it as prose. Word processors, some note apps and some chat tools may replace straight quotation marks with curly ones or alter whitespace, and curly quotes make the JSON invalid. Behavior varies by application and settings; this article has not tested specific destinations, so check the one you rely on by pasting a sample and running it through a parser.
Readability is a separate concern from validity. Minified JSON is hard for people to scan, and heavily escaped strings such as \u00e9 in place of é are harder still. Raw JSON is also likely to be awkward with screen readers, since the meaning depends on punctuation and nesting that may be read out symbol by symbol or skipped depending on verbosity settings. No assistive-technology testing is available for this article. When people, rather than programs, are the audience, provide a plain-text or tabular summary alongside the JSON, or pretty-print it with literal Unicode characters.
Search and editing follow the same pattern. Text search inside a JSON file will not find é if the file stores it as \u00e9, and editing escaped text by hand is error-prone. Choosing literal characters where your toolchain supports UTF-8 keeps files easier to search and edit.
Deserializing untrusted input
Standard JSON parsers produce only plain data, so parsing JSON does not run code the way deserializing some language-specific formats can; Python's pickle, for instance, is documented as unsafe for untrusted data. JSON still needs care. Parse with a real JSON parser rather than evaluating text as code, then validate the resulting structure, types and value ranges before using it, for example with a JSON Schema validator or explicit checks. In JavaScript, be cautious when merging parsed objects into existing ones: a key named proto in the input can lead to prototype pollution if a naive merge function copies it.
Gaps in this review
The behavior described here comes from the JSON specification and the documented behavior of JavaScript's built-in JSON object and Python's json module. No performance measurements, comparisons of specific third-party libraries or online formatters, or tests of particular paste destinations or assistive technologies were available. Other languages and libraries may handle dates, large numbers, special floating-point values and duplicate keys differently, so check their documentation before assuming the same results.