Back to Updates
DevTool Team

Converting CSV to JSON: Headers, Type Inference, and CJK Garbled Text, Explained

Why does CSV to JSON keep going wrong in the details? This guide walks the real failure points: header rows, long ID precision, garbled CJK characters from Excel exports, delimiter detection — then converts it right in one pass with an online tool, with the reverse JSON-to-CSV direction covered too.

Why CSV to JSON fails in the details

CSV looks like the simplest format — comma-separated, one record per line. But the failures are all in the details: order IDs turning into scientific notation, CJK characters from Excel becoming question marks, a comma inside a value splitting a row in half, headerless files eating the first data row as field names. Each trap maps to a rule in the CSV spec or the encoding layer; once you know the rules, conversion goes from luck to certainty.

Fastest path first: the CSV to JSON tool makes the common decisions correct by default — delimiter auto-detection, type inference, 16+ digit integers kept as strings, BOM stripped automatically. Paste and you have results. The rest of this guide explains the rules behind those defaults so you know when to adjust.

Headers: is the first row field names or data

Every item in a JSON array is an object, so where field names come from is decision one:

  • First row is the header (most common): name,age becomes "name", "age" keys. Empty header cells need fallback names (this tool uses column_N) and duplicates need disambiguation (_2, _3), or object keys silently overwrite each other.
  • No header: field names auto-generate as column_1, column_2... Count columns by the widest row in the whole file — counting only the first row silently drops trailing fields of longer rows, the most common silent bug of headerless mode.

Copy a range out of Excel/WPS and you get tab-separated (TSV) text, not commas — a good converter sniffs this automatically, no pre-conversion needed.

Type inference: what becomes a number, what must stay a string

Everything in CSV is text; JSON has types. Inference rules determine output quality:

Raw CSV Result Why
30 30 (number) ordinary numbers convert
true / false boolean case-insensitive
007 "007" (string) leading zeros would be lost as numbers
9223372036854775807 string 16+ digits exceed Number precision (2^53)
empty cell null / "" / omitted three policies; pick by your consumer's contract

Order IDs, snowflake IDs, and ID numbers are the disaster zone: JS Number is exact only to 2^53-1; a 19-digit snowflake ID converted to a number gets zeros in its last digits. The rule of thumb is simple: 16+ digits means string. If the downstream system wants every field as a string, just disable type inference for all-strings output.

Quoted fields are another rule: the comma in "Smith, John" is part of the value, not a separator — RFC 4180-compliant parsers handle this; a hand-rolled split(',') fails here.

Garbled CJK text: it's the encoding, not the tool

"CSV to JSON garbled characters" is a high-frequency search, but the corruption happens before conversion — the file encoding is wrong:

  1. Excel's "Save as CSV" may default to ANSI/GBK (it follows system locale), while web tools read UTF-8. GBK bytes decoded as UTF-8 become mojibake or replacement characters.
  2. Fix: choose "CSV UTF-8" when saving from Excel; or paste through VS Code (the encoding shows bottom-right, switchable) and confirm UTF-8 before copying into the tool.
  3. BOM: Windows Notepad/Excel UTF-8 CSVs usually carry a BOM (\uFEFF), which pollutes the first field name invisibly. A proper tool strips it.

This site's tool detects replacement characters (the signature of non-UTF-8 decoding) and tells you to re-save as CSV UTF-8 instead of leaving you staring at mojibake.

The one-pass workflow

The CSV to JSON tool defaults to everything this guide recommends: header on, type inference on (with leading-zero and big-integer protection), empty cells as null. Three steps: paste or upload → adjust options if needed (header off, all-strings, drop columns) → copy or download the .json.

Two common follow-ups: pretty inspection goes to the site's JSON Formatter; converting back (edited data returning to a spreadsheet) goes to JSON to CSV with aligned semantics so round-trips lose nothing. If the source is an Excel file rather than CSV, Excel to JSON handles multiple sheets and merged cells.

Frequently Asked Questions

What's the fastest way to convert CSV to JSON?

An online converter is the least effort: paste your CSV into the site's CSV to JSON tool — delimiters auto-detected, numbers/booleans/empty cells type-inferred — then copy or download the .json file. Everything runs locally in your browser; nothing is uploaded.

How do I fix garbled characters when converting CSV to JSON?

The root cause is encoding: Excel's default "Save as CSV" often writes ANSI/GBK while web tools read UTF-8. Re-save as "CSV UTF-8", or paste the content through an editor like VS Code confirmed to be UTF-8. This site's tool warns directly when the input looks non-UTF-8.

Long numeric order IDs lose precision after converting — what now?

That's JavaScript's Number precision limit (2^53). Integers of 16+ digits must be carried as strings. Have the tool keep them as strings (this site's tool does by default), or turn off type inference entirely for all-strings output.

How do I convert CSV without a header row?

Turn off "First row is header"; field names auto-generate as column_1, column_2 through the last column. Count columns by the widest row in the file — using only the first row silently drops trailing fields of longer rows.