The failure mode: a round trip nobody planned
It usually starts innocently. Someone exports a row from a web service, drops it into Excel or Google Sheets, and one column happens to hold an entire JSON object — an event payload, a webhook body, a configuration blob. JSON is a single line of text as far as the spreadsheet is concerned, so it lands in one cell without complaint. The trouble begins when that cell travels back out.
Spreadsheets were built for names, dates, and currency amounts, not for text where every quotation mark and newline must survive byte for byte. Between the paste and the re-export, several silent transformations occur. Quotes inside the JSON get doubled when the CSV writer escapes the field. Actual newlines inside pretty-printed JSON break the row into several physical lines, so the "one record, one row" assumption collapses. Numbers get "helped": a product code like 0042197 loses its leading zeros the moment the cell is treated as numeric, and a large identifier like 718545440000512 may come back as 7.18545E+14 because the sheet decided to display it in scientific notation.
The result looks hopeless. It rarely is. The damage is systematic, which means it can be reversed systematically — provided you work in stages rather than stabbing at the text with a text editor. This guide walks through four stages: establish how the JSON was copied, extract the intended field from the CSV container, validate what you extracted, and reformat it for reading.
Stage 1: establish what was copied
Before touching the text, figure out the transport path. There are three common routes by which JSON ends up in a spreadsheet, and each leaves a different fingerprint of damage.
Clipboard paste. Someone copied JSON output from a terminal or browser and pasted it into a cell. If the JSON was pretty-printed, each line may have landed in a separate row, because spreadsheets treat newlines as row separators on paste. If it was single-line, it probably survived in one cell — though numbers may have been silently converted.
CSV export from the spreadsheet. This is where the classic mangling happens. The CSV writer must escape the JSON field to keep the file parseable, and the escaping it chooses — doubling quote characters, wrapping the field in quotes, embedding or flattening newlines — is invisible until you know the rules. Excel in particular has historically written UTF-8 with a BOM and used locale-dependent delimiters.
Direct download from the source system. Sometimes the CSV never passed through a spreadsheet at all — the backend serialized a table column straight to CSV. This is usually the least damaged form, because the writer tends to be a library with correct RFC 4180 behavior. If you can get the file this way, do it.
Ask the person who sent you the file which path it took. One question saves an hour of guesswork: did you open this in Excel at any point? If yes, assume number mangling until proven otherwise. If no, the container is probably intact and only the JSON inside it needs attention.
Stage 2: extract the intended CSV field
The mangled JSON you are staring at is not the original payload; it is the original wrapped in a CSV quoting envelope, possibly opened and re-saved by a spreadsheet along the way. Stage 2 removes that envelope correctly instead of eyeballing it.
The RFC 4180 quoting rules
CSV looks trivial and is not. RFC 4180, the closest thing the format has to a specification, defines three rules that matter here. First, a field containing a comma, a quote, or a line break must be enclosed in double quotes. Second, a quote inside such a field is escaped by doubling it. Third, a quoted field may contain line breaks; they belong to the field, not to the row structure.
A JSON payload trips all three rules at once — quotes around every key and string value, commas between members, and newlines in pretty-printed variants. So an order record exported to CSV arrives looking like this, with the entire JSON crammed into the last quoted field:
1043,2026-11-14,"{""order_id"": ""0042197"", ""customer"": ""O'Brien, Maria"", ""total"": 149.50}",shipped
Every quote you see doubled is a single quote in the real data. The comma inside O'Brien, Maria is protected by the outer quotes and must not split the field. If you naively split this line on commas, you get six fragments instead of four, and the JSON is shredded in a way no amount of quote repair can undo — structural information about where the field actually ends is lost.
Extraction is parsing, not searching
The correct move is to run a real CSV parse over the file and pick out the column that holds the JSON, rather than hunting for the JSON with string operations. A proper parser consumes the quoting rules and hands you the unescaped field: doubled quotes collapsed back to singles, embedded newlines restored, commas kept inside the field. In pseudocode:
rows = csv_parse(file_text) # RFC 4180 aware parser
row = rows[row_number] # one logical row, not one physical line
field = row[column_index] # the cell holding the JSON payload
print(length(field)) # plausibly complete?
Every serious language ships a CSV parser that follows these rules: Python's csv module, Ruby's CSV, Go's encoding/csv, Java's commons-csv. What you must not do is line.split(",") or a hand-rolled scan for the first and last quote. The parser already encodes decades of edge cases, including fields with a quote not at the field boundary — a state some Excel exports produce and most parsers tolerate only grudgingly.
One caution: if the JSON was pretty-printed before the paste, a single logical row spans multiple physical lines. Feed the whole file to the parser, not line by line, or you will parse fragments of a quoted field as complete rows.
Stage 3: validate the extracted text as JSON syntax
Once the field is out of its CSV envelope, you have a candidate JSON document. Do not assume it is valid — validate it, and let the validator pinpoint each recognizable damage pattern:
- Doubled quotes that survived. If extraction missed some escaping (common when someone partially hand-repaired the file before you got it), the parser stops at the first
""inside a string. - Literal escape artifacts. Some tools flatten newlines into visible backslash sequences inside JSON strings. Whether that is damage or intended depends on the original payload — check before "fixing" it.
- Truncated structure. If a cell hit a length limit (older Excel versions capped cells at 32,767 characters), the JSON may simply end mid-object. "Unexpected end of input" at the last character is the signature of truncation, and no local repair recovers what was cut.
- Unquoted or requoted numbers. Numeric mangling can produce tokens that are not valid JSON numbers, like
1,234.56with a thousands separator, which the parser flags as an unexpected comma.
Validate after every repair attempt, not just once at the start. A repair that introduces new damage gets caught immediately instead of surfacing three steps later when the data fails to load.
Stage 4: reformat for reading
With a valid document in hand, the last stage is presentation. Payloads that spent time in a spreadsheet are usually single-line minified JSON — right for machines, miserable for humans. Reformat with consistent indentation so you can read what you recovered and compare it against the schema or the source system.
This is also the moment to check the numbers you care about. Leading zeros never survive a numeric interpretation, so an ID like 0042197 that was quoted in the original JSON can still have been damaged if someone retyped it into the sheet. Compare recovered values against the source of truth: re-fetch one record, or diff against a second export. Recovery is not complete until the payload is not merely parseable but correct.
A fully worked example
Let's run the whole pipeline on a concrete, fictional case. An events team exported a webhook log to CSV and emailed it around. One row holds a JSON payload describing a shipment update, occupying the third of four fields:
88231,2026-11-14T09:12:44Z,"{""event"": ""shipment.updated"", ""shipment"": {""id"": ""0057441"", ""route"": ""TPA > MEM > ORD"", ""weight_kg"": 4.2e1, ""notes"": ""Left at receiving dock\nRing bell twice""}}",delivered
Running a real CSV parser over the file and pulling field three yields the unescaped cell content:
{"event": "shipment.updated", "shipment": {"id": "0057441", "route": "TPA > MEM > ORD", "weight_kg": 4.2e1, "notes": "Left at receiving dock\nRing bell twice"}}
This is parseable JSON — but not necessarily faithful JSON. Inspecting the values raises three flags. The shipment ID 0057441 has leading zeros, plausible because it arrived quoted and the CSV envelope protected it — good. The route string contains > characters, which is fine, but if the export had been HTML-escaped we would see > here instead. And weight_kg holds 4.2e1: scientific notation for what was almost certainly 42 — the signature of a spreadsheet having touched the value. The \n inside notes, by contrast, is legitimate JSON escaping for a two-line note and should be left alone.
After correcting the mangled number back to 42 (verified against the source system, not guessed) and pretty-printing, the recovered payload reads:
{
"event": "shipment.updated",
"shipment": {
"id": "0057441",
"route": "TPA > MEM > ORD",
"weight_kg": 42,
"notes": "Left at receiving dock\nRing bell twice"
}
}
The whole rescue took four operations: parse the CSV envelope, extract one field, validate, repair one value with evidence, reformat. Note what we did not do: edit the raw line by hand, or trust a value we could not corroborate.
Why fixing quotes by hand is the last resort
When people see doubled quotes, the instinct is to open the file in a text editor and start deleting. Resist it. Manual repair scales terribly — a log with four hundred rows means four hundred rounds of mistake-prone editing — and it fails silently: delete one quote too many and the field's boundaries shift, corrupting everything after it in ways harder to detect than the original problem. Hand editing is appropriate exactly once: a single row, extraction impossible, validation immediately after. Even then, work on a copy.
The regexes that almost work
The second instinct is to reach for a regular expression — s/""/"/g to collapse doubled quotes, or a clever pattern to strip the outer envelope. These regexes almost work, which is worse than not working. Applied to a payload with adjacent JSON strings written without spaces, like {"a":1,"b":2}, the sequence ,""b" contains a doubled quote that is not an escape, and the regex destroys it. A pattern matching from the first quote to the last on a line is correct for single-field rows and catastrophic when the JSON is one of several quoted fields, because the match swallows the delimiters between them.
The deeper problem is that CSV quoting is context-free grammar territory, not regular expression territory. A quote's meaning depends on whether the parser is inside or outside a quoted field, and regular expressions cannot track that state reliably. This is the same class of mistake as parsing XML with regex — it works on the six examples you tested and detonates on the seventh. Use the parser. If you find yourself writing a regex with more than one quote character in it to process CSV, stop and reconsider.
There is a related trap on the JSON side: confusion between JSON string escapes and CSV escapes. The sequence \" inside a JSON string is a JSON escape; "" inside a CSV field is a CSV escape. Files that went through both layers can carry both at once, and collapsing the wrong layer first produces garbage that looks superficially plausible. Always strip the outermost envelope first, validate, then decide whether the next layer needs attention. Our guide on forward slash escaping covers how these escape layers stack.
Spreadsheet number mangling and how to prevent it
The most damaging transformations in the pipeline are also the quietest. When a spreadsheet ingests text, it makes a type guess per cell, and its guesses are optimized for accountants, not programmers. Three guesses cause the worst losses.
Leading zeros vanish. A cell containing 0042197 is interpreted as the number 42197. The zeros are not hidden — they are gone, irrecoverably, from the stored value. The classic victims are ZIP codes, SKUs, order IDs, and anything "a number" only by accident of its characters.
Large integers lose precision. A 64-bit identifier such as 718545440000512 exceeds the precision a spreadsheet keeps for numbers (roughly 15 significant decimal digits), so the low-order digits are replaced with zeros — and the display switches to scientific notation like 7.18545E+14. The original bits no longer exist in the file.
Dates and fractions get rewritten. A string like 2026-11-14 may be converted to a serial date and re-exported in the sheet's locale format — 11/14/2026, 14.11.2026, or a five-digit serial number. Values like 1e5 inside a recovered payload are almost always scars from this process.
Prevention is to never let the spreadsheet interpret the column in the first place. When importing CSV, use the import dialog's per-column type controls and set the JSON column (and any ID columns) to text, not general. Excel's "Data → From Text/CSV" offers this; Google Sheets' import dialog allows forcing text per column. If someone must paste JSON into a sheet, have them format the destination cells as text first. When a round trip is unavoidable, zip the raw CSV so no application ever opens it.
Number mangling is destructive and invisible. If a recovered payload contains a numeric ID whose digits look suspicious — trailing zeros that were not in the original, or an exponent — do not "fix" it by editing. Re-export from the source with the column forced to text. Guessing digits back into an identifier produces data that parses cleanly and lies.
When the JSON was already broken before the CSV step
Not every wound in a recovered payload came from the spreadsheet. Sometimes the payload was malformed at birth — truncated by a logging bug, hand-assembled by string concatenation, or produced by a serializer that emitted invalid JSON — and the CSV trip merely preserved the damage faithfully. Diagnosing which layer wounded the payload changes what you do next.
Damage from the CSV layer has fingerprints: doubled quotes in CSV-escape positions, newlines aligned with pretty-printing structure, scientific notation in numbers. Damage that predates the CSV has different ones: an object that ends mid-key, unescaped control characters from a hand-built string, single quotes as string delimiters, or trailing commas left by a templating system. If the syntax errors you find do not match the CSV fingerprints, suspect the source.
When the source itself was broken, the honest options shrink. You can repair by hand if the document is small and the intent obvious, but you are now editing data, not recovering it, and the result should be marked as reconstructed. If the payload came from a service, re-request it — the CSV copy is a lossy photocopy, and the original is usually one API call away. If broken payloads are produced routinely by a system you control, fix the producer; a structured error format like the one in our guide on problem details errors makes failures legible instead of leaving them to be excavated from log CSVs months later.
Symptom, cause, fix: a recovery cheat sheet
The table below condenses the guide into the patterns you are most likely to meet, in the order you meet them.
| Symptom in the text | Likely cause | Fix |
|---|---|---|
Every quote in the JSON appears doubled (""key"") | The field is still inside its CSV quoting envelope | Run a real CSV parser and take the unescaped field — do not delete quotes by hand |
| One record is smeared across several physical lines | Pretty-printed JSON was pasted in; newlines split the row on paste | Parse the whole file with an RFC 4180 parser so embedded newlines stay inside the field |
| Field boundaries look wrong; commas split mid-value | Naive comma-splitting destroyed quoted fields | Re-extract from the original file with a CSV parser before any repair |
ID reads 42197 instead of 0042197 | The cell was interpreted as a number; leading zeros dropped | Recover from source; re-import with the column forced to text |
Number shows as 7.18545E+14 | Large integer exceeded spreadsheet precision and display switched to scientific notation | Re-fetch the original value; the digits are gone from this copy |
| Validator says "unexpected end of input" | The payload was truncated (cell length limit or source bug) | Compare with the source system; local repair cannot restore missing text |
| Validator flags a doubled quote after extraction | Partially hand-repaired file, or both JSON and CSV escaping present | Strip the outermost envelope first, validate, then address the next layer |
Test it yourself
Every stage above is something you can rehearse in five minutes. Export a small CSV containing one quoted JSON field, run it through your language's CSV parser, and inspect the extracted field's length and contents. Then paste the extracted text into the JSON Inspector to validate syntax and pretty-print the result. Deliberately break a copy — double the quotes again, or reformat a number in scientific notation — and confirm the validator catches each mutation. Practicing on payloads you corrupted yourself, where the original is known, builds an eye for CSV scars fastest.
One last habit worth forming: whenever you send JSON to someone who might touch it with a spreadsheet, send two artifacts — the raw file, untouched, and a plain-text preview of the payload. The recipient gets the readable copy for their eyes and the faithful copy for the machine, and the two never meet inside a grid of cells. For payloads that reference positions inside nested structures, our guide on JSON Pointer escapes covers how to keep paths stable when keys contain tricky characters.
Reproduce every example locally with the JSON Inspector or the matching tool on the workbench. Nothing you paste leaves your browser.