JSON vs CSV vs XML: Choosing a Data Format and Converting Between Them

Strengths and limits of JSON, CSV and XML, what gets lost when you convert between them, and how to avoid the most common conversion bugs.

JSON: the default for APIs

JSON represents objects, arrays, strings, numbers, booleans and null. It maps directly onto data structures in almost every programming language, which is why it dominates web APIs and configuration files. It supports nesting naturally, so a customer with a list of orders, each with a list of items, fits in one document.

Its limits are worth knowing: there is no date type (dates travel as strings, ideally ISO 8601), no comments, and numbers are usually parsed as 64-bit floats, so integers above 2^53 (about 9 quadrillion) lose precision in JavaScript. Large IDs such as Twitter-style snowflakes should be sent as strings.

CSV: the default for tables

CSV stores rows and columns as plain text. Every spreadsheet, database and BI tool can import it, it compresses well and it streams easily, so it is the practical choice for exports, bulk loads and handing data to non-developers.

CSV has no types and no nesting. Everything is a string until something interprets it, which is how spreadsheets turn ZIP codes like 02134 into 2134 and long numbers into scientific notation. RFC 4180 defines quoting rules (fields containing commas, quotes or line breaks must be wrapped in double quotes, and embedded quotes are doubled), but many tools deviate, especially around delimiters in locales that use a comma as the decimal separator.

XML: the default for documents and legacy integrations

XML is verbose but expressive. It distinguishes attributes from child elements, supports namespaces for mixing vocabularies, and can be validated strictly against an XSD schema. That is why it persists in SOAP services, banking (ISO 20022), travel and healthcare standards, office file formats and RSS feeds.

When you parse XML from untrusted sources, disable external entity resolution. XML External Entity (XXE) attacks use entity declarations to read local files or make network requests from the parsing server, and many older parsers enable entities by default.

What gets lost in conversion

JSON to CSV forces a tree into a grid. Nested objects must be flattened into dotted column names (address.city), and arrays either become repeated rows, numbered columns (items.0.name, items.1.name) or a JSON string inside a cell. Each choice suits different consumers, so decide based on who reads the CSV.

CSV to JSON loses nothing structurally but gains no types: every value arrives as a string unless the converter infers numbers and booleans, and inference can be wrong (a product code of 1e5 becomes 100000). XML to JSON has to decide how to represent attributes and repeated elements; a single child element and a list of one child can come out differently, which breaks code expecting an array.

Conversion checklist

Validate the source before converting; a trailing comma or unescaped quote produces confusing output downstream. Check that the character encoding is UTF-8, and watch for a byte-order mark at the start of CSV files exported from Excel. Confirm how empty values, nulls and missing keys are represented on both sides. Spot-check rows containing commas, quotes, line breaks and non-ASCII characters, since those reveal quoting bugs.

For sensitive data, convert locally rather than uploading files to a remote service. Browser-based converters process the file on your machine, so customer exports and internal reports never leave it.

JSON Formatter & Converter