Stax
Tools

CSV to JSON Converter

Convert CSV data to JSON array instantly.

CSV กับ JSON — เมื่อไหร่ควรใช้อันไหน

ผลลัพธ์ที่ได้มีลักษณะอย่างไร

ดูเพิ่มเติม

CSV (Comma-Separated Values) เหมาะสำหรับข้อมูลตารางใน spreadsheet, การ export จากฐานข้อมูล และ pipeline ด้านวิทยาศาสตร์ข้อมูล มันกะทัดรัดและอ่านได้ง่ายสำหรับข้อมูลแบบ flat JSON (JavaScript Object Notation) เหมาะสำหรับ API, web app และข้อมูลที่มีโครงสร้างซ้อนกัน การแปลงจาก CSV เป็น JSON เป็นขั้นตอนทั่วไปเมื่อนำเข้าข้อมูล spreadsheet ไปยัง JavaScript หรือ Node.js application

จาก CSV นี้:

{`name,age,city\nAlice,30,Mumbai\nBob,25,Delhi`} JSON output จะเป็น:

{`[\n { "name": "Alice", "age": "30", "city": "Mumbai" },\n { "name": "Bob", "age": "25", "city": "Delhi" }\n]`} หมายเหตุ: ค่าทั้งหมดเป็น string ใน output ถ้าต้องการ type ตัวเลข ให้ใช้ JSON.parse กับ reviver หรือใช้ library อย่าง Zod สำหรับ type coercion

ต้องการทำตรงกันข้าม?{" "} JSON to CSV Converter แปลง JSON array กลับเป็นไฟล์ CSV ที่ดาวน์โหลดได้

Data engineer นำเข้า spreadsheet ที่ export จากเครื่องมืออย่าง Google Sheets หรือ Tally ไปยัง Node.js pipeline โดยแปลง CSV เป็น JSON ก่อน นักพัฒนา frontend ใช้ JSON array ที่ได้จากไฟล์ข้อมูล CSV เพื่อเติม mock API และ local state วิศวกร QA แปลงตารางข้อมูลทดสอบจาก Excel เป็น JSON fixture สำหรับชุดทดสอบอัตโนมัติ นักวิเคราะห์ที่ทำงานกับ Python pandas สามารถ export DataFrame เป็น CSV จากนั้นแปลงเป็น JSON สำหรับการประมวลผล JavaScript ในขั้นตอนถัดไป ทีมผลิตภัณฑ์ตั้งค่าเว็บไซต์ที่จัดการโดย content โดยสร้างข้อมูลใน Google Sheets และแปลงเป็น JSON สำหรับ static site generator

CSV ไม่มีระบบ type แบบ native — ค่าทั้งหมดเป็น string เมื่อแปลงเป็น JSON ค่าทั้งหมดจะปรากฏเป็น string literal แม้จะดูเหมือนตัวเลขหรือ boolean ตัวอย่างเช่น ค่า CSV 30 กลายเป็น JSON string{" "} "30" แทนที่จะเป็นตัวเลข 30 ถ้าโค้ดปลายทางของคุณคาดหวัง typed value ให้ทำการแปลงหลังจากการแปลง: ใน JavaScript ใช้ +row.age หรือ Number(row.age) เพื่อ coerce field ตัวเลข; ใช้ row.active === 'true' เพื่อ coerce boolean Library อย่าง Zod และ Valibot ทำสิ่งนี้ได้อย่างปลอดภัยด้วย schema validation ในเวลา parse

ตัวคั่นสี่ตัวที่รองรับ (comma, tab, semicolon, pipe) ครอบคลุมไฟล์ CSV ส่วนใหญ่ในโลกจริง Comma เป็นมาตรฐานสำหรับ export ใน locale ภาษาอังกฤษส่วนใหญ่ Semicolon ปรากฏใน Excel และ LibreOffice ที่ใช้ locale ยุโรปซึ่ง comma ใช้เป็นตัวคั่นทศนิยม Tab-separated value (TSV) พบได้ทั่วไปใน export จากฐานข้อมูลและไฟล์ข้อมูลทางวิทยาศาสตร์ ไฟล์ Pipe-delimited ใช้ใน EDI (electronic data interchange) บางรูปแบบและ format ข้อมูลทางการเงิน เลือกตัวคั่นที่ถูกต้องก่อนแปลง — ตัวคั่นที่ไม่ตรงกันจะให้ output คอลัมน์เดียวแทนที่จะเป็นหลายคอลัมน์

คำถามที่พบบ่อย

How does CSV to JSON conversion work?
Each CSV row becomes a JSON object. The first row (if 'first row is header' is enabled) becomes the keys for each object. Subsequent rows provide the values. The result is a JSON array of objects, which is the most common format for APIs, databases, and JavaScript applications.
How are quoted fields with commas handled?
RFC 4180-compliant CSV wraps fields that contain the delimiter character in double quotes. For example: Alice,"New York, NY",30 — the city field contains a comma but is quoted. This converter correctly handles quoted fields, including escaped quotes (two double-quotes inside a quoted field represent a single quote).
What delimiters are supported?
This converter supports the four most common delimiters: comma (,) for standard CSV, tab (\t) for TSV files exported from Excel or Google Sheets, semicolon (;) common in European locale exports, and pipe (|) used in some data interchange formats.
What if my CSV has no header row?
Uncheck 'First row is header'. The converter will auto-generate column names as column_1, column_2, column_3, etc. You can then rename these in your code or data processing pipeline.
Is my data uploaded to a server?
No. This converter runs entirely in your browser. Your CSV data is processed locally using JavaScript and never sent to any server. This makes it safe for sensitive or confidential data.

เครื่องมือที่เกี่ยวข้อง