Skip to content
cosmodev ~/tools/json-csv

Trình chuyển đổi JSON ↔ CSV

Converters & Formatters

Chuyển mảng JSON các đối tượng sang CSV và ngược lại. Xử lý trường trong ngoặc kép, dấu phẩy nhúng, ký tự xuống dòng và ngoặc kép thoát (RFC 4180). 100% trong trình duyệt.

CSV
Dán JSON để xem kết quả chuyển sang CSV.

(Tài liệu bằng tiếng Anh)

What it does

Converts between JSON and CSV in both directions. JSON → CSV takes an array of objects (or a single object) and produces a table: the union of all keys becomes the header row, and one row follows per object. CSV → JSON parses RFC 4180 quoting and rebuilds an array of objects. A Swap button flips the direction and carries the output across as the new input, so a document round-trips without copy and paste. A stat line under the grid counts rows or items and the output size in bytes.

How to use it

  1. Pick a direction with the segmented control: JSON → CSV or CSV → JSON. Swap does the same and moves the current output into the input.
  2. Paste your document into the left pane.
  3. The converted result appears live on the right. Copy takes it.
  4. Read the stat line: N rows · M bytes for JSON → CSV, N items · M bytes for CSV → JSON.

Examples

[{"name":"ada","role":"admin"},{"name":"bob","role":"user"}]

becomes:

name,role
ada,admin
bob,user

Stat line: 2 rows · 28 bytes.

A field containing a comma, a quote, or a newline is quoted per RFC 4180: [{"price":"1,000"}] becomes price on the header line and "1,000" on the data line. CSV → JSON reverses the quoting exactly.

How the table model works

Both formats express the same shape: a table of rows with named columns. JSON spells it an array of objects; CSV spells it a header line plus one line per record:

Concept JSON CSV
table array of objects the whole file
column object key header entry
row one object one line
cell value field

JSON → CSV walks the input once and collects every key it meets, in order of first appearance, as the header. An object missing a key gets an empty cell.

That is where the formats stop being equivalent, because CSV cells are plain text:

  • A nested object or array becomes its string form ([object Object], 1,2) and does not come back.
  • Numbers and booleans become text: the value 1 round-trips as the string "1".
  • An empty CSV cell reads back as "".

So JSON → CSV → JSON is lossy whenever values are more than plain strings or numbers. Use the pair for tabular data, and keep nested documents in JSON.

Good to know

  • Deterministic: column order follows first appearance of each key; output uses \n line breaks with no trailing newline.
  • Round-trip check: convert one way, hit Swap, convert back, and diff the two documents to see exactly what a spreadsheet would keep.
  • Private: all conversion runs locally in your browser.
  • Related tools: JSON Formatter, JSON Validator, JSON Minify.
Mã nguồn14 ngôn ngữ

100% phía client · dữ liệu của bạn không bao giờ rời khỏi trình duyệt. Thấy hữu ích? Chia sẻ với đồng nghiệp của bạn.