Checking a JSON-looking value inside a CSV field
A CSV cell can hold text that looks exactly like a JSON object. Converting the CSV to JSON keeps that text as a string, and this worksheet shows the quoting rules that make it work.
Two formats, one cell
CSV and JSON are different formats with different rules, and a cell can contain text written in the second while sitting inside the first. The cell in this worksheet holds the characters {"x":1}. To a person it looks like a small JSON object. To a CSV parser it is only the content of a field, a run of characters to be returned as text. The CSV to JSON converter reads the CSV layer, produces a string for the field, and writes that string into JSON output, where its quotation marks are escaped. At no point does it look inside the string and build a nested object from it. The same layering applies to XML, HTML or a SQL statement stored in a cell, which are also only text to a CSV parser. For the cell in this worksheet, the header row names the column payload, and the single data row holds the quoted field, so the output contains one object with one key.
How the cell is written in CSV
The standard description of CSV, RFC 4180, says that a field containing a double quotation mark, a comma or a line break must be enclosed in double quotes, and that a double quote inside such a field is written as two double quotes. The text {"x":1} contains quotation marks, so the field must be enclosed, and each inner quote is doubled. The result is the line "{""x"":1}" with one outer pair and doubled inner pairs. The worksheet source has a header line payload and then this quoted field. The doubled quotes are a CSV escape, and they disappear when the parser reads the field. Opening the raw file in a plain text editor and not in a spreadsheet shows the real quoting, which is the best way to see what was written. The rule is easy to remember as quote doubling: every quotation mark inside a quoted field becomes two, and the outer pair is added around the whole field.
What the parser returns
After CSV parsing, the field contains the characters left brace, quote, x, quote, colon, 1, right brace. That is seven characters, and they form valid JSON syntax when read as a document. The converter, however, treats them as string content. In its JSON output the row is an object with the key payload, and the value is a string whose quotation marks must be written with backslashes. The output shows payload followed by the string with backslash-quote around the x. Reading the JSON back with a JSON parser gives the same seven characters, still as a string, not as an object with a property named x. The converter keeps the quotation marks and braces as characters, so the string length is seven even though a person reads it as one small object.
Why no recursion happens
A converter that parsed embedded JSON automatically would need to guess which fields contain it. A field with braces might be JSON, a template placeholder, or a code snippet. Guessing wrong would change data without warning, and a failed guess on malformed content would raise confusing errors. Keeping the field as text is predictable: what goes in comes out. If a downstream program wants to treat the cell as JSON, it can run a JSON parser on the string explicitly, with its own validation and error handling. It also avoids the cost and risk of parsing very large cells that nobody asked to be parsed. The same principle applies to any guess about what a cell means: deciding that a field is a number, a date or an object is the job of a schema.
The separate JSON check
The control case passes the same seven characters to the JSON validator formatter as a document. With an indentation of zero it returns {"x":1} and reports it as valid, which shows that the text is well-formed JSON on its own. The check confirms that the cell content is parseable if someone chooses to parse it. It does not change what the CSV converter did. The two tools answer different questions about the same characters, one at the CSV layer and one at the JSON layer. The same text with a missing closing brace would fail the JSON check but would still pass through the CSV converter unchanged, because the CSV layer does not validate it.
Commas inside the embedded text
A JSON object with more than one member contains commas, and commas are CSV separators. The text {"a":1,"b":2} written unquoted in a CSV line would be split into several fields at the comma. Quoting the field protects the comma, and the inner quotation marks are doubled as before: "{""a"":1,""b"":2}". The quoted form returns the full text as one field. Spreadsheet programs and libraries that write CSV add the quotes automatically, which is why exported files often look cluttered with doubled quotes. The clutter is a faithful escape and not a sign of corruption. If a file has more fields in some rows than in others, an unquoted comma inside embedded JSON is a likely cause.
Newlines inside a field
Pretty-printed JSON spans several lines, and line breaks are another reason for CSV quoting. RFC 4180 allows a quoted field to contain line breaks, and the parser keeps them as part of the value. A cell holding multi-line JSON then comes out of the converter as a string with newline characters, which the JSON output writes as backslash n. Some simple tools split a CSV file by lines before parsing and fail on such cells. The converter used here follows the quoting rules, so a quoted multi-line cell stays in one field. Windows tools usually end records with carriage return and line feed, and a cell value may contain bare line feeds, so both forms can coexist in one file.
Schema decisions belong downstream
Whether a column should be a string, a number or a nested object depends on the application. An API may expect payload as a string of serialized JSON and parse it later. A reporting tool may want it as a real object. Both are legitimate, and the choice should be written in a schema or contract and applied by a deliberate transformation step. Valid JSON syntax in the cell does not settle the schema question, since a cell can contain valid JSON that the receiving system would reject for its content. A data contract that states payload is a JSON string removes the question for everyone who reads the file later.
Common mistakes to avoid
One mistake is to forget the doubled quotes and write the cell as "{"x":1}", which breaks the CSV structure because the parser sees the field end after the first inner quote. Another is to paste the cell through a word processor or a text field with smart punctuation, which can convert quote characters to curly typographic marks that are not valid in JSON. A third is to run a JSON parser on the whole CSV file. A fourth is to read the escaped JSON output and mistake the backslashes for part of the data. They are escapes that disappear when the string is read. A related mistake is to open the CSV in a text editor, fix the quotes by hand and save it in an encoding that changes other characters. Checking the file with a small sample before converting thousands of rows catches quoting problems cheaply.
Round trips and verification
To confirm that nothing was lost, convert the CSV to JSON, parse the JSON, take the payload string, and compare it with the original cell text. They should match character for character. If you then parse the payload string as JSON, the result should be an object with x equal to 1. Doing each step separately shows which layer introduced any difference. The worksheet results follow this path. The CSV step yields a string, and the independent JSON check shows that the string is itself valid JSON. A character-for-character comparison also catches changes to whitespace, which is invisible on screen but present in the data.
Where this pattern shows up
Cells containing serialized JSON appear whenever structured data is exported to a flat file. A database column of JSON type exported to CSV writes each object as text. A spreadsheet of web analytics events may keep the raw event payload in one column beside readable columns. Logging tools often dump a structured record into one field. In each case the CSV file is a faithful container, and the JSON inside is just text until a program parses it. Knowing this helps when a column seems to contain an object that the converter refused to expand. The converter is behaving correctly, and the expansion step is yours to add. Because the content stays text, a search for a key inside the payload column can be done with a plain text filter, but a precise query needs the payload parsed first.
Reading the escaped output
The JSON output spells the cell as a string literal. The seven characters of the cell become nine inside the outer quotation marks, because each of the two inner quotes needs a backslash: backslash quote x backslash quote. Counting the outer quotes gives eleven characters in the output spelling. Reading a JSON parser result of this string gives back the seven characters. The backslashes belong to the output syntax and not to the data. If you see backslashes in a database value after loading, a layer has probably been escaped twice, which is the sign of text that was serialized, stored as a string and serialized again.
Reproduce the checks
CSV layer
Open the Csv To Json Converter and enter:
- CSV input
payload "{""x"":1}"- First row contains headers
true
Expected output:
Rows
[
{
"payload": "{\"x\":1}"
}
]The embedded value remains a JSON string.
Separate JSON syntax control
Open the Json Validator Formatter and enter:
- JSON input
{"x":1}- Indent
0
Expected output:
Formatted
{"x":1}The same text can be checked independently as a document.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08
- Primary definition and convention reference ↗ · 2026-10-08