PRACTICAL WORKFLOW GUIDE

Convert JSON to CSV Without Losing Leading Zeros

Move JSON API records into CSV while understanding field unions, missing values, long identifiers and spreadsheet import behavior.

Try the actual tool: Open the JSON to CSV Converter

JSON API data often comes as an array of objects, while spreadsheets expect columns and rows. Conversion is straightforward until a product ID contains leading zeros, records have different fields, or one object includes an array. Those cases need an explicit rule rather than blindly splitting on commas.

This guide demonstrates what the LocalCSV Lab converter does, where CSV loses type information, and how to avoid accidental changes when opening the result in spreadsheet software. The conversion happens in your browser, with no upload required.

Example input and expected output

Source data

[{"order_id":"000123","sku":"BM-1","price":12.5},{"order_id":"000124","sku":"RC-2","region":"KR"}]

After the conversion

order_id,sku,price,region
000123,BM-1,12.5,
000124,RC-2,,KR

Step-by-step workflow

  1. Check that the source is a JSON array of objects. A single object must be wrapped inside square brackets to become an array.
  2. Open the JSON to CSV Converter linked below and paste the sample input or choose a JSON file stored on your device.
  3. Select a comma delimiter for a conventional CSV. Semicolon and tab delimiters are available when a destination system expects them.
  4. Leave spreadsheet formula protection enabled if you will open the CSV in a spreadsheet application.
  5. Process the conversion, inspect the result, download CSV, and tell your spreadsheet importer that identifiers such as order_id should be imported as Text.

Leading zeros are a data-type problem, not just a CSV problem

The input string "000123" remains the CSV text 000123. However, CSV has no native text type. Spreadsheet software may parse that cell as the number 123 when you double-click a CSV file. To retain leading zeros in a spreadsheet, use a data-import workflow and explicitly select Text for identifier columns.

A JSON number cannot legally be written as 000123. If a product code, postal code or account-like identifier has leading zeros, make it a quoted JSON string in the source. The tool will not recreate zeroes that were already removed upstream.

Different objects can have different keys

A list of API objects does not require every object to have the same field names. In the example above, the first record has price but the second has region. The converter creates the union of both records' keys, ordered by their first appearance, and writes empty cells for missing fields.

Missing fields and explicit null values both become empty CSV cells. If downstream software needs to distinguish null from missing or an empty string, use JSON directly or define a separate sentinel value before conversion.

Nested values stay in a single cell

A nested object such as {"gift":true} or an array such as ["red","blue"] is serialized to compact JSON text inside one CSV field. The CSV writer quotes that field and escapes embedded quote marks. It does not explode arrays into several rows or create paths such as address.city automatically.

If an analysis requires deep flattening, define its schema first: choose whether one nested element becomes a separate row, a dotted column, or a JSON string. Automatic flattening without a schema can silently duplicate records and is intentionally outside this converter's scope.

Guard against spreadsheet formulas and unsafe numeric precision

The converter adds an apostrophe to text that looks like a spreadsheet formula, including risky column names. It protects against values starting with =, +, - or @ after leading whitespace. This changes the text representation for CSV export, so disable protection only for trusted machine-only pipelines.

Standard JavaScript JSON parsing uses floating-point numbers. A large integer outside the safe integer range may be rounded before the output is generated. Represent large tracking IDs as quoted strings in JSON, and test a small sample before converting the full file.

Frequently asked questions

Can I upload a JSON file?

Yes, up to 2 MB. The local browser editor reads it on your device without sending the file to the website.

Why does one record have blank CSV cells?

Different records can have different keys. Blank output cells stand in for missing properties or JSON null.

Does it handle an array of arrays?

No. It expects an array of objects. Create named fields in each object before conversion.

Related tools

Back to all data guides