CSV to JSON
Convert CSV rows into JSON objects
CSV to JSON — what it does
Turn a CSV file into a JSON array of objects, using the header row as the property names for every record. It is the format shift you need whenever tabular data has to reach an API, a JavaScript application or a configuration file that has no concept of rows and columns.
Worked example
A five-row staff export, contacts.csv, converted as it is; the header row supplies the property names of every object.
Input — contacts.csv
name,email,department,start_date,salary Ann Lee,ann.lee@example.com,Sales,2021-03-15,52000 Ben Ortiz,ben.ortiz@example.com,Engineering,2019-11-02,88000 Chloe Park,chloe.park@example.com,Sales,2023-06-01,47500 Dev Patel,dev.patel@example.com,Support,2020-01-20,41000 Emma Rossi,emma.rossi@example.com,Engineering,2022-09-12,91000
Output — JSON array (first 3 of 5 records shown)
[
{
"name": "Ann Lee",
"email": "ann.lee@example.com",
"department": "Sales",
"start_date": "2021-03-15",
"salary": "52000"
},
{
"name": "Ben Ortiz",
"email": "ben.ortiz@example.com",
"department": "Engineering",
"start_date": "2019-11-02",
"salary": "88000"
},
{
"name": "Chloe Park",
"email": "chloe.park@example.com",
"department": "Sales",
"start_date": "2023-06-01",
"salary": "47500"
},
… (2 more records)
]Every value stays a string — "salary": "52000" is quoted — and the output shown here is cut after three records; the page shows all five.
When this tool helps
- Preparing seed or fixture data for an application from a spreadsheet a colleague maintains.
- Building a request body for an API that accepts a bulk array of records.
- Moving a lookup table into a static site or front-end bundle as a JSON asset.
How to use it
- Choose the CSV file.
- Let the tool parse the header and rows.
- Review the JSON in the output panel.
- Copy or save the JSON for your project.
Accuracy, limits, and good practice
- Every value comes through as a string, because CSV carries no type information. Cast numbers and booleans on the receiving side if it matters.
- Header names become object keys verbatim, so headers with spaces or punctuation produce keys that need bracket notation in code.
- Empty cells become empty strings rather than null; treat that distinction deliberately if your schema separates blank from missing.
Frequently asked questions
Can I get nested JSON?
Not directly. Convert to a flat array first, then reshape it — the JSON flattener and path extractor help with the reverse direction.
What if my CSV has no header row?
Add one first. Without headers there are no key names, and the first data row would be consumed as labels.
Is the output valid JSON?
Yes. Quotes, backslashes and line breaks inside values are escaped so the result parses in any JSON reader.
What happens if two header cells have the same name?
The later column wins. Objects are built from header/value pairs in order, so when two headers are both called email, only the value from the second email column survives and the first is lost without warning.
What if a row has fewer or more cells than the header?
Missing cells become empty strings, so a short row still gets every key. Cells beyond the header count are dropped, because only the header positions are read. Completely blank lines are skipped and produce no object.
Related tools on this site
- CSV Viewer — Open and inspect CSV files
- JSON to CSV — Convert an array of JSON objects into CSV
- CSV Duplicate Remover — Remove duplicate rows using a selected key column
Further reading: Cleaning a CSV export before you import it anywhere · CSV, JSON, YAML, XML and Markdown Tables: When Each Fits and How to Convert
Everything above runs inside this page. CSV to JSON needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
CSV 轉 JSON能做什麼
把 CSV 檔案轉成 JSON 物件陣列,並以標題列作為每筆紀錄的屬性名稱。當表格資料必須送進 API、JavaScript 應用程式,或送進沒有「列與欄」概念的設定檔時,這就是必要的格式轉換。
實際範例
五列員工名單 contacts.csv 原樣轉換;標題列成為每個物件的屬性名稱。
輸入:contacts.csv
name,email,department,start_date,salary Ann Lee,ann.lee@example.com,Sales,2021-03-15,52000 Ben Ortiz,ben.ortiz@example.com,Engineering,2019-11-02,88000 Chloe Park,chloe.park@example.com,Sales,2023-06-01,47500 Dev Patel,dev.patel@example.com,Support,2020-01-20,41000 Emma Rossi,emma.rossi@example.com,Engineering,2022-09-12,91000
輸出:JSON 陣列(5 筆中只列出前 3 筆)
[
{
"name": "Ann Lee",
"email": "ann.lee@example.com",
"department": "Sales",
"start_date": "2021-03-15",
"salary": "52000"
},
{
"name": "Ben Ortiz",
"email": "ben.ortiz@example.com",
"department": "Engineering",
"start_date": "2019-11-02",
"salary": "88000"
},
{
"name": "Chloe Park",
"email": "chloe.park@example.com",
"department": "Sales",
"start_date": "2023-06-01",
"salary": "47500"
},
… (2 more records)
]所有值都保留為字串,例如 "salary": "52000" 仍帶引號;此處在第三筆後截斷,頁面上會完整顯示五筆。
什麼時候用得上
- 從同事維護的試算表,產生應用程式的種子或測試資料。
- 為接受批次陣列的 API 準備請求內容。
- 把對照表以 JSON 資產的形式放進靜態網站或前端打包檔。
使用步驟
- 選擇 CSV 檔案。
- 由工具解析標題與資料列。
- 在輸出區檢視 JSON。
- 複製或儲存 JSON 供專案使用。
精確度、限制與實務建議
- 所有值都會以字串輸出,因為 CSV 本身不帶型別資訊;若型別重要,請在接收端自行轉型。
- 標題會原樣成為物件鍵名,含空格或標點的標題在程式中需用中括號語法存取。
- 空白儲存格會變成空字串而非 null;若你的結構要區分「空白」與「缺漏」,請特別留意。
常見問題
可以產生巢狀 JSON 嗎?
無法直接產生。請先轉成平面陣列再自行重組;反方向可用 JSON 扁平化與路徑提取工具處理。
CSV 沒有標題列怎麼辦?
請先補上標題。沒有標題就沒有鍵名,第一列資料會被當成標籤吃掉。
輸出是合法 JSON 嗎?
是。值中的引號、反斜線與換行都會逸出,任何 JSON 解析器都能讀取。
兩個標題欄位同名會怎樣?
後面的欄位會蓋掉前面的。物件是依序由「標題/值」配對組成,若兩個標題都叫 email,只會留下第二個 email 欄的值,第一個會無聲消失。
某一列的儲存格比標題少或多會怎樣?
缺少的儲存格會變成空字串,所以短列仍然擁有全部的鍵。超出標題欄數的儲存格會被捨棄,因為只讀取標題對應的位置。完全空白的行會被略過,不會產生物件。
本站相關工具
- CSV 檢視器 — 開啟並檢視 CSV 內容
- JSON 轉 CSV — 將 JSON 物件陣列轉換成 CSV
- CSV 重複資料移除 — 依指定欄位移除重複資料列
延伸閱讀: 匯入之前先把 CSV 匯出檔清乾淨 · CSV、JSON、YAML、XML 與 Markdown 表格:各自適用的場合與轉換方法
以上步驟全部在這個頁面內完成,CSV 轉 JSON 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。