Data Formats

JSON Array vs CSV vs Line List: Which Format Should You Use?

Compare JSON arrays, CSV, and line lists. Learn about escaping, nested data, spreadsheet use, and conversion pitfalls for your data projects.

When you work with lists of data for spreadsheets, APIs, or developer tools, you often choose between a few simple text formats. JSON arrays, CSV files, and line lists (one item per line) are among the most common. Each format has strengths and limitations that affect how you handle escaping, nested structures, and human editing.

JSON arrays are machine–friendly and support rich data types; CSV is the universal format for spreadsheet import and export; line lists are the simplest for manual editing and version control. The right choice depends on whether you need to preserve structure, share with non–technical users, or minimise file size.

This guide compares the three formats across escaping, nested data, spreadsheet integration, and conversion pitfalls. You will learn how to use each format effectively and avoid common mistakes when moving data between them.

Understanding the Three Formats

A JSON array is an ordered collection of values enclosed in square brackets. It can contain strings, numbers, booleans, objects, and nested arrays. CSV (comma‑separated values) represents tabular data as rows of fields separated by commas, often with an optional header row. A line list is the simplest form: one value per line, no delimiters, no column structure.

  • JSON arrays handle heterogeneous data and nested objects.
  • CSV is the standard for spreadsheet and database exports.
  • Line lists are best for simple, ordered collections like email addresses or filenames.
JSON array example
["apple", "banana", "cherry"]
CSV example
fruit,quantity
apple,3
banana,5
cherry,2
Line list example
apple
banana
cherry

Working with JSON Arrays

JSON arrays are widely used in web APIs and configuration files because they support nested structures. An array can hold objects with multiple properties, making it easy to represent real‑world entities. The format is strict: trailing commas, unquoted keys, or mismatched brackets will cause parsing errors.

For simple lists, JSON is more verbose than a line list, but its machine readability and support for diverse data types often outweigh the overhead. Escaping is handled with backslashes inside strings: double quotes become \", backslashes become \\, and newlines become \n.

  • Pros: supports complex nesting, language independent, self‑describing.
  • Cons: more verbose, requires validation, less human‑editable for large datasets.
JSON array of objects
[
  {"name": "Alice", "email": "[email protected]"},
  {"name": "Bob", "email": "[email protected]"}
]
JSON with escaped characters
["line1\nline2", "path\\to\\file", "She said \"hello\""]

Working with CSV

CSV files are the de facto standard for exchanging data between spreadsheets and databases. Each line represents a record, and fields are separated by a delimiter—typically a comma, though semicolons are used in regions where the comma is a decimal separator. Following RFC 4180, fields containing a delimiter, a double quote, or a newline must be enclosed in double quotes.

Data in CSV is always represented as strings; numbers, dates, and booleans may be interpreted differently by different programs. Headers are common but not mandatory. The biggest challenge with CSV is handling locale‑specific delimiters and encoding (UTF‑8, UTF‑8 BOM, or ISO‑8859‑1).

  • Pros: native to spreadsheets, easy to view in table form, compact.
  • Cons: limited data types (all strings), no nested structures, quote escaping can be confusing.
CSV with headers and quoted field
"Name","Comment"
"Smith, John","He said ""hello"""

Working with Line Lists

A line list is the simplest text‑based data format: one value per line, no delimiters, no quoting rules. It is ideal for collections of items where each item is a single string without newlines, such as email addresses, domain names, filenames, or product codes. The format is extremely human‑friendly and works well with command‑line tools like grep, sort, and uniq.

Because there is no escaping, line lists cannot contain multiline values. If an item might include a newline, you must either use a different format or encode the newline as a literal backslash‑n (or another placeholder) by convention. Many editors and version‑control systems handle line lists cleanly because each change is visible line by line.

  • Pros: human‑readable, easy to sort and deduplicate, no escaping for typical values.
  • Cons: only suitable for single‑field data, no support for multiline items without conventions.
Line list of email addresses
[email protected]
[email protected]
[email protected]

Escaping and Quoting Across the Three Formats

Each format handles special characters differently. In JSON, any string can contain backslash‑escaped sequences: \" for a double quote, \\ for a backslash, \n for newline, \t for tab. The parser always interprets these sequences, which makes JSON unambiguous but harder to write by hand.

CSV relies on outer double quotes to protect fields that contain special characters. If a field contains a double quote, it is doubled ("" becomes a single literal quote). Line lists have no escape mechanism; if the data contains a newline, the structure breaks. Understanding these differences is critical when converting between formats.

  • JSON uses backslash escaping inside strings.
  • CSV uses double‑quoting for fields containing commas, newlines, or quotes.
  • Line lists assume no newlines in data; embedded newlines are not representable.
Same data in JSON and CSV
JSON: "He said \"hello\"\nand left."
CSV: "He said ""hello""
and left."

Spreadsheet Integration and Import/Export

CSV is the most straightforward format for spreadsheet users. Most spreadsheet applications (Microsoft Excel, Google Sheets, LibreOffice Calc) can open a CSV file directly, though they may misinterpret the delimiter or encoding. For consistent results, save CSV files in UTF‑8 with a Byte Order Mark (BOM) and use commas (or semicolons as required by region).

JSON arrays can be imported into spreadsheets using built‑in tools like Power Query (Excel) or by writing a short script. Line lists are often pasted into a single column; you may need to use the ‘Text to Columns’ feature if the list contains delimiters. For each format, watch out for automatic data conversion: leading zeros in numbers, date strings, or large numbers that may lose precision.

  1. Open Excel and choose File > Open.
  2. Select your CSV file. If the data appears incorrectly, use the Text Import Wizard to specify delimiter and encoding.
  3. For JSON, use Data > Get Data > From File > From JSON.
  4. For a line list, paste the data into a column, then select the column and use Data > Text to Columns if you need to split further.
  • CSV: verify the delimiter and character encoding; UTF-8 with a BOM can improve compatibility with some Excel versions.
  • JSON: validate the structure before importing so syntax errors are caught early.
  • Line list: paste into a text-formatted column when leading zeroes must be preserved.

Common Conversion Pitfalls and How to Avoid Them

Converting between these formats often causes data loss if you are not careful. Flattening a nested JSON array to CSV forces you to choose which properties to keep, discarding others. When converting a line list to CSV, each line becomes a single field, but if the line contains a comma or double quote, it must be properly quoted to remain a single column.

Validation is key. JSON files should be validated with a linter to catch trailing commas or unquoted keys. CSV files should be checked for consistent row lengths and correct quoting. Line lists should have trailing newlines and no blank lines unless intended. Using a dedicated conversion tool can help avoid these pitfalls.

  1. 1. Identify the source format's structure (flat or nested).
  2. 2. If converting from JSON, flatten any nested objects or arrays.
  3. 3. For CSV, ensure headers are present if needed and that fields are correctly quoted.
  4. 4. For line lists, confirm that items do not contain newlines; if they do, encode them or switch format.
  5. 5. Validate the output with a simple parsing test.
  • Flatten nested objects in JSON before converting to CSV.
  • Always quote fields in CSV if they may contain commas or newlines.
  • Validate JSON with a linter before conversion.
  • Check for empty lines or trailing spaces in line lists.
Bad conversion: JSON to CSV without flattening
Source JSON: [{"name": "Alice", "tags": ["dev", "admin"]}]
Flattened CSV: name,tags
Alice,"[""dev"",""admin""]"
Correctly quoted CSV field with comma
"Name"
"Smith, John"

Choosing a Format: Decision Guide

The best format for your data depends on how it will be created, consumed, and maintained. Use JSON arrays when your data has nested structures, or when you are exchanging data between applications that already use JSON. Choose CSV when your target audience uses spreadsheets, or when you need a universally accepted tabular format. Pick a line list for simple, flat collections that humans will edit with a basic text editor.

  • For API data → JSON.
  • For spreadsheet import → CSV.
  • For plain lists (emails, codes) → line list.
  • For maximum interoperability → CSV (all spreadsheet apps support it).
  • For version‑friendly diffs → line list.

Conclusion

Choose JSON for structured or nested application data, CSV for true rows and columns, and a line list for a simple flat collection whose values do not contain line breaks. Escaping and import behavior matter as much as the visible delimiter.

Browser list converters are useful for primitive JSON arrays and literal delimiter changes. Use a proper CSV parser for quoted or multiline CSV and validate the destination format before discarding the source.

FAQ

Frequently asked questions

Can I store nested data in CSV?+

CSV is strictly flat; it cannot represent arrays or nested objects. If you need to preserve a hierarchical structure, use JSON or a format like YAML.

Why do my CSV files show garbled characters in Excel?+

Excel often expects UTF‑8 with a Byte Order Mark (BOM) for non‑ASCII characters. Save your CSV as UTF‑8 with BOM, or use a semicolon delimiter if that is the default for your locale.

How do I convert a JSON array to a line list?+

If the array contains simple values (strings, numbers), extract each value to a line. For objects, you must choose a property to flatten, discarding other properties. Use a tool like json‑array‑to‑list to automate this.

What does a comma inside a CSV field look like?+

The field must be enclosed in double quotes, for example: "Smith, John". If the field contains a double quote, represent it as two double quotes: "He said ""hello""".

Is it safe to use a line list for data that may contain newline characters?+

No, because a newline would break the structure. Either use a format that supports escaping, such as JSON or CSV, or encode newlines as a placeholder (e.g., the literal characters \n) and document the convention clearly.

Can I use CompareTwoLists to convert between these formats?+

CompareTwoLists can convert a flat line list to or from a JSON array of primitive values, and it can join or split text with a literal comma delimiter. The comma tools are not full RFC-style CSV parsers: quoted fields, embedded delimiters, headers, and multiline records require spreadsheet import or a real CSV library.

Related tools

Popular list tools

Browse all tools →

Guides

Related guides

Back to all guides →