Guide
From nested JSON to flat CSV rows
By Logappradeep · ServiceNow developer
CSV (comma-separated values) is the lowest common denominator for tabular data. Spreadsheets, BI tools, CRMs, and database import wizards all accept it, even when they cannot read JSON. Converting JSON to CSV makes API data easy to sort, filter, chart, and share with people who live in Excel or Google Sheets.
What shape of JSON works
The natural input is an array of objects, where each object becomes a row and each key a column. A single object is also accepted and becomes one row. Real API data is rarely flat, so the converter flattens nested values:
- Nested objects become dot-notation columns:
{"address": {"city": "London"}}produces a column namedaddress.city. - Arrays of simple values are joined into one cell separated by semicolons:
["a", "b"]becomesa; b. - Arrays of objects become indexed columns such as
orders.0.skuandorders.1.sku. nullbecomes an empty cell.
[
{"id": 1, "name": "Ada", "address": {"city": "London"}, "tags": ["a", "b"]},
{"id": 2, "name": "Linus", "email": "linus@example.com"}
]
becomes:
id,name,address.city,tags,email
1,Ada,London,a; b,
2,Linus,,,linus@example.com
The header row is the union of keys across all rows, in the order they first appear, so a field present only in later records still gets its own column. Values containing commas, double quotes, or line breaks are wrapped in double quotes, and embedded quotes are doubled, following the conventions described in RFC 4180.
Problems you will meet with real data
- Wide tables from long arrays. Arrays of objects with many entries create many indexed columns. If each array item should be its own row, reshape the data into one record per item before converting.
- Spreadsheets reinterpret values. Excel strips leading zeros from ZIP codes and phone numbers, shows long IDs in scientific notation, and turns strings like
3-4into dates. Import the file with column types set to text when that matters. - Formula injection. Cells beginning with
=,+,-, or@may be executed as formulas when the file is opened in a spreadsheet. If the data comes from users, sanitize those values before sharing the export. - Character encoding. Some Excel versions assume a legacy encoding for CSV files, which garbles accented characters. Importing through the Data menu and choosing UTF-8 avoids this.
- Round trips are lossy. Once flattened, the CSV no longer records which values were numbers, booleans, or arrays, so converting back will not restore the original structure exactly.
Common uses
Exporting API results for a stakeholder report, preparing contact or product lists for a bulk import, loading test data into a spreadsheet for review, and turning log events into a table for quick analysis.
The conversion runs live in your browser, so customer records and other sensitive rows are not uploaded.