[{"data":1,"prerenderedAt":820},["ShallowReactive",2],{"guide-csv-json-conversion-guide":3},{"id":4,"title":5,"body":6,"date":808,"description":809,"extension":810,"meta":811,"navigation":347,"path":815,"readingTime":816,"seo":817,"stem":818,"__hash__":819},"guides\u002Fguides\u002Fcsv-json-conversion-guide.md","CSV to JSON Conversion Guide: Transform Your Data",{"type":7,"value":8,"toc":795},"minimark",[9,14,18,21,25,28,39,42,81,85,88,252,255,259,262,295,302,400,403,407,410,413,472,475,524,527,531,534,588,592,673,684,688,691,723,727,747,751,754,764,768,791],[10,11,13],"h2",{"id":12},"what-is-csv-to-json-conversion","What Is CSV to JSON Conversion?",[15,16,17],"p",{},"CSV (Comma-Separated Values) and JSON (JavaScript Object Notation) are two of the most common data formats. CSV stores tabular data as plain text rows, while JSON represents structured data as key-value pairs. Converting between them lets you move data between spreadsheets, APIs, databases, and web applications.",[15,19,20],{},"You might convert CSV to JSON when importing spreadsheet data into a web API. You might go the other direction when exporting API responses into a report. Both directions have quirks that trip up developers.",[10,22,24],{"id":23},"csv-structure-basics","CSV Structure Basics",[15,26,27],{},"A CSV file is deceptively simple — rows of values separated by commas. But the format has rules that many people overlook.",[29,30,35],"pre",{"className":31,"code":33,"language":34},[32],"language-text","name,age,city\nAlice,30,New York\nBob,25,\"Los Angeles\"\nCarol,,Chicago\n","text",[36,37,33],"code",{"__ignoreMap":38},"",[15,40,41],{},"Key elements:",[43,44,45,53,59,65,75],"ul",{},[46,47,48,52],"li",{},[49,50,51],"strong",{},"Header row",": The first row typically defines column names.",[46,54,55,58],{},[49,56,57],{},"Delimiter",": Commas are standard, but tabs (TSV) and semicolons are common in European locales.",[46,60,61,64],{},[49,62,63],{},"Quoting",": Fields containing commas, line breaks, or quotes must be wrapped in double quotes.",[46,66,67,70,71,74],{},[49,68,69],{},"Escaping",": A double quote inside a quoted field becomes two double quotes — ",[36,72,73],{},"\"He said \"\"hello\"\"\"",".",[46,76,77,80],{},[49,78,79],{},"Missing values",": Empty fields between delimiters represent null or empty data.",[10,82,84],{"id":83},"json-structure-for-tabular-data","JSON Structure for Tabular Data",[15,86,87],{},"JSON represents tabular data as an array of objects. Each object corresponds to one row, with keys drawn from the CSV headers.",[29,89,93],{"className":90,"code":91,"language":92,"meta":38,"style":38},"language-json shiki shiki-themes github-light github-dark","[\n  {\n    \"name\": \"Alice\",\n    \"age\": 30,\n    \"city\": \"New York\"\n  },\n  {\n    \"name\": \"Bob\",\n    \"age\": 25,\n    \"city\": \"Los Angeles\"\n  },\n  {\n    \"name\": \"Carol\",\n    \"age\": null,\n    \"city\": \"Chicago\"\n  }\n]\n","json",[36,94,95,104,110,127,140,151,157,162,174,186,196,201,206,218,230,240,246],{"__ignoreMap":38},[96,97,100],"span",{"class":98,"line":99},"line",1,[96,101,103],{"class":102},"sVt8B","[\n",[96,105,107],{"class":98,"line":106},2,[96,108,109],{"class":102},"  {\n",[96,111,113,117,120,124],{"class":98,"line":112},3,[96,114,116],{"class":115},"sj4cs","    \"name\"",[96,118,119],{"class":102},": ",[96,121,123],{"class":122},"sZZnC","\"Alice\"",[96,125,126],{"class":102},",\n",[96,128,130,133,135,138],{"class":98,"line":129},4,[96,131,132],{"class":115},"    \"age\"",[96,134,119],{"class":102},[96,136,137],{"class":115},"30",[96,139,126],{"class":102},[96,141,143,146,148],{"class":98,"line":142},5,[96,144,145],{"class":115},"    \"city\"",[96,147,119],{"class":102},[96,149,150],{"class":122},"\"New York\"\n",[96,152,154],{"class":98,"line":153},6,[96,155,156],{"class":102},"  },\n",[96,158,160],{"class":98,"line":159},7,[96,161,109],{"class":102},[96,163,165,167,169,172],{"class":98,"line":164},8,[96,166,116],{"class":115},[96,168,119],{"class":102},[96,170,171],{"class":122},"\"Bob\"",[96,173,126],{"class":102},[96,175,177,179,181,184],{"class":98,"line":176},9,[96,178,132],{"class":115},[96,180,119],{"class":102},[96,182,183],{"class":115},"25",[96,185,126],{"class":102},[96,187,189,191,193],{"class":98,"line":188},10,[96,190,145],{"class":115},[96,192,119],{"class":102},[96,194,195],{"class":122},"\"Los Angeles\"\n",[96,197,199],{"class":98,"line":198},11,[96,200,156],{"class":102},[96,202,204],{"class":98,"line":203},12,[96,205,109],{"class":102},[96,207,209,211,213,216],{"class":98,"line":208},13,[96,210,116],{"class":115},[96,212,119],{"class":102},[96,214,215],{"class":122},"\"Carol\"",[96,217,126],{"class":102},[96,219,221,223,225,228],{"class":98,"line":220},14,[96,222,132],{"class":115},[96,224,119],{"class":102},[96,226,227],{"class":115},"null",[96,229,126],{"class":102},[96,231,233,235,237],{"class":98,"line":232},15,[96,234,145],{"class":115},[96,236,119],{"class":102},[96,238,239],{"class":122},"\"Chicago\"\n",[96,241,243],{"class":98,"line":242},16,[96,244,245],{"class":102},"  }\n",[96,247,249],{"class":98,"line":248},17,[96,250,251],{"class":102},"]\n",[15,253,254],{},"This structure is what most APIs expect when you send tabular data.",[10,256,258],{"id":257},"csv-to-json-the-parsing-algorithm","CSV to JSON: The Parsing Algorithm",[15,260,261],{},"Converting CSV to JSON follows these steps:",[263,264,265,271,277,283,289],"ol",{},[46,266,267,270],{},[49,268,269],{},"Read the header row"," — split on the delimiter to get column names.",[46,272,273,276],{},[49,274,275],{},"Read each data row"," — split on the delimiter, respecting quoting rules.",[46,278,279,282],{},[49,280,281],{},"Map values to keys"," — pair each value with its corresponding header.",[46,284,285,288],{},[49,286,287],{},"Handle types"," — convert numeric strings to numbers, empty strings to null, and quoted values to strings.",[46,290,291,294],{},[49,292,293],{},"Collect rows into an array"," — build the final JSON array.",[15,296,297,298,301],{},"The critical step is splitting correctly. A naive ",[36,299,300],{},"split(\",\")"," breaks on every comma, including commas inside quoted fields.",[29,303,307],{"className":304,"code":305,"language":306,"meta":38,"style":38},"language-javascript shiki shiki-themes github-light github-dark","\u002F\u002F Naive — breaks on quoted commas\nconst values = row.split(\",\");\n\n\u002F\u002F Correct — use a proper CSV parser\nimport Papa from 'papaparse';\nconst result = Papa.parse(csvString, { header: true, dynamicTyping: true });\n","javascript",[36,308,309,315,343,349,354,371],{"__ignoreMap":38},[96,310,311],{"class":98,"line":99},[96,312,314],{"class":313},"sJ8bj","\u002F\u002F Naive — breaks on quoted commas\n",[96,316,317,321,324,327,330,334,337,340],{"class":98,"line":106},[96,318,320],{"class":319},"szBVR","const",[96,322,323],{"class":115}," values",[96,325,326],{"class":319}," =",[96,328,329],{"class":102}," row.",[96,331,333],{"class":332},"sScJk","split",[96,335,336],{"class":102},"(",[96,338,339],{"class":122},"\",\"",[96,341,342],{"class":102},");\n",[96,344,345],{"class":98,"line":112},[96,346,348],{"emptyLinePlaceholder":347},true,"\n",[96,350,351],{"class":98,"line":129},[96,352,353],{"class":313},"\u002F\u002F Correct — use a proper CSV parser\n",[96,355,356,359,362,365,368],{"class":98,"line":142},[96,357,358],{"class":319},"import",[96,360,361],{"class":102}," Papa ",[96,363,364],{"class":319},"from",[96,366,367],{"class":122}," 'papaparse'",[96,369,370],{"class":102},";\n",[96,372,373,375,378,380,383,386,389,392,395,397],{"class":98,"line":153},[96,374,320],{"class":319},[96,376,377],{"class":115}," result",[96,379,326],{"class":319},[96,381,382],{"class":102}," Papa.",[96,384,385],{"class":332},"parse",[96,387,388],{"class":102},"(csvString, { header: ",[96,390,391],{"class":115},"true",[96,393,394],{"class":102},", dynamicTyping: ",[96,396,391],{"class":115},[96,398,399],{"class":102}," });\n",[15,401,402],{},"Always use a CSV parser library in production. Hand-rolled splitting logic fails on edge cases.",[10,404,406],{"id":405},"json-to-csv-the-flattening-problem","JSON to CSV: The Flattening Problem",[15,408,409],{},"Going from JSON to CSV is not always a simple reverse. JSON supports nested objects and arrays — CSV is flat. You must decide how to handle nested data.",[15,411,412],{},"Consider this JSON:",[29,414,416],{"className":90,"code":415,"language":92,"meta":38,"style":38},"{\n  \"name\": \"Alice\",\n  \"address\": {\n    \"city\": \"New York\",\n    \"zip\": \"10001\"\n  }\n}\n",[36,417,418,423,434,442,453,463,467],{"__ignoreMap":38},[96,419,420],{"class":98,"line":99},[96,421,422],{"class":102},"{\n",[96,424,425,428,430,432],{"class":98,"line":106},[96,426,427],{"class":115},"  \"name\"",[96,429,119],{"class":102},[96,431,123],{"class":122},[96,433,126],{"class":102},[96,435,436,439],{"class":98,"line":112},[96,437,438],{"class":115},"  \"address\"",[96,440,441],{"class":102},": {\n",[96,443,444,446,448,451],{"class":98,"line":129},[96,445,145],{"class":115},[96,447,119],{"class":102},[96,449,450],{"class":122},"\"New York\"",[96,452,126],{"class":102},[96,454,455,458,460],{"class":98,"line":142},[96,456,457],{"class":115},"    \"zip\"",[96,459,119],{"class":102},[96,461,462],{"class":122},"\"10001\"\n",[96,464,465],{"class":98,"line":153},[96,466,245],{"class":102},[96,468,469],{"class":98,"line":159},[96,470,471],{"class":102},"}\n",[15,473,474],{},"Two common strategies:",[476,477,478,494],"table",{},[479,480,481],"thead",{},[482,483,484,488,491],"tr",{},[485,486,487],"th",{},"Strategy",[485,489,490],{},"CSV Output",[485,492,493],{},"Trade-off",[495,496,497,511],"tbody",{},[482,498,499,503,508],{},[500,501,502],"td",{},"Dot notation",[500,504,505],{},[36,506,507],{},"name,address.city,address.zip",[500,509,510],{},"Flat headers, readable",[482,512,513,516,521],{},[500,514,515],{},"JSON string",[500,517,518],{},[36,519,520],{},"name,address",[500,522,523],{},"Preserves structure, not human-readable",[15,525,526],{},"Dot notation is the most practical approach for most use cases. Deeply nested data or arrays of objects may require custom flattening logic.",[10,528,530],{"id":529},"edge-cases-that-break-conversions","Edge Cases That Break Conversions",[15,532,533],{},"These scenarios cause most conversion errors:",[43,535,536,545,554,560,566,572,578],{},[46,537,538,119,541,544],{},[49,539,540],{},"Commas inside quoted fields",[36,542,543],{},"\"Smith, Jr.\",30"," — a naive split produces three values instead of two.",[46,546,547,550,551,74],{},[49,548,549],{},"Line breaks in quoted fields",": A single CSV row can span multiple lines if a quoted field contains ",[36,552,553],{},"\\n",[46,555,556,559],{},[49,557,558],{},"Inconsistent quoting",": Some rows quote a field, others do not. Parsers handle this, but manual splits fail.",[46,561,562,565],{},[49,563,564],{},"Missing columns",": A row with fewer values than headers — the parser must pad with nulls.",[46,567,568,571],{},[49,569,570],{},"Extra columns",": A row with more values than headers — the parser must either ignore or create dynamic keys.",[46,573,574,577],{},[49,575,576],{},"Encoding issues",": BOM markers, non-UTF-8 encodings, and special characters cause silent corruption.",[46,579,580,583,584,587],{},[49,581,582],{},"Numeric vs string ambiguity",": CSV has no type system. ",[36,585,586],{},"\"12345\""," could be a string or a number. JSON requires you to choose.",[10,589,591],{"id":590},"common-errors-and-fixes","Common Errors and Fixes",[476,593,594,607],{},[479,595,596],{},[482,597,598,601,604],{},[485,599,600],{},"Error",[485,602,603],{},"Cause",[485,605,606],{},"Fix",[495,608,609,620,629,640,651,662],{},[482,610,611,614,617],{},[500,612,613],{},"Misaligned columns",[500,615,616],{},"Unquoted commas in fields",[500,618,619],{},"Use a proper CSV parser",[482,621,622,625,627],{},[500,623,624],{},"Broken rows",[500,626,549],{},[500,628,619],{},[482,630,631,634,637],{},[500,632,633],{},"Wrong data types",[500,635,636],{},"Numbers stored as strings",[500,638,639],{},"Enable dynamic typing in your parser",[482,641,642,645,648],{},[500,643,644],{},"Lost nested data",[500,646,647],{},"Flattening drops objects",[500,649,650],{},"Use dot-notation flattening",[482,652,653,656,659],{},[500,654,655],{},"Encoding corruption",[500,657,658],{},"Non-UTF-8 source files",[500,660,661],{},"Convert encoding before parsing",[482,663,664,667,670],{},[500,665,666],{},"Silent nulls",[500,668,669],{},"Empty fields mapped to empty strings",[500,671,672],{},"Explicitly map empty strings to null",[15,674,675,676,679,680,683],{},"The single most impactful fix: stop writing your own CSV splitter. Use a library like PapaParse (JavaScript), Python's ",[36,677,678],{},"csv"," module, or Ruby's ",[36,681,682],{},"CSV"," class.",[10,685,687],{"id":686},"conversion-workflow-tips","Conversion Workflow Tips",[15,689,690],{},"Follow these practices for reliable conversions:",[43,692,693,699,705,711,717],{},[46,694,695,698],{},[49,696,697],{},"Validate before converting"," — check that headers exist, row lengths are consistent, and encoding is UTF-8.",[46,700,701,704],{},[49,702,703],{},"Preserve types explicitly"," — define which columns are strings, numbers, or dates before parsing.",[46,706,707,710],{},[49,708,709],{},"Handle errors gracefully"," — log rows that fail to parse instead of silently skipping them.",[46,712,713,716],{},[49,714,715],{},"Test with real data"," — synthetic test data rarely contains the quoting edge cases that break production.",[46,718,719,722],{},[49,720,721],{},"Round-trip check"," — convert CSV to JSON and back, then diff the result. Mismatches reveal parsing bugs.",[10,724,726],{"id":725},"key-takeaways","Key Takeaways",[43,728,729,732,735,738,741,744],{},[46,730,731],{},"CSV and JSON serve different purposes — tabular storage versus structured data interchange.",[46,733,734],{},"Naive comma splitting fails on quoted fields, embedded line breaks, and inconsistent quoting.",[46,736,737],{},"Always use a CSV parser library instead of writing your own split logic.",[46,739,740],{},"JSON-to-CSV conversion requires flattening nested objects — dot notation is the most practical approach.",[46,742,743],{},"Empty fields, type ambiguity, and encoding mismatches are the most common sources of silent data corruption.",[46,745,746],{},"Validate, convert, then validate again — the round-trip test catches most conversion bugs.",[10,748,750],{"id":749},"try-it-yourself","Try It Yourself",[15,752,753],{},"Convert your CSV and JSON files in seconds:",[43,755,756],{},[46,757,758,763],{},[759,760,762],"a",{"href":761},"\u002Ftools\u002Fcsv-json","CSV to JSON Converter"," — Convert CSV to JSON and JSON to CSV with delimiter and type options",[10,765,767],{"id":766},"related-guides","Related Guides",[43,769,770,777,784],{},[46,771,772,776],{},[759,773,775],{"href":774},"\u002Fguides\u002Fdata-format-comparison","Data Format Comparison: CSV, JSON, XML, and YAML"," — Side-by-side comparison of all four formats",[46,778,779,783],{},[759,780,782],{"href":781},"\u002Fguides\u002Fdata-transformation-tools","Data Transformation Tools"," — Essential converters and validators for developer workflows",[46,785,786,790],{},[759,787,789],{"href":788},"\u002Fguides\u002Fjson-vs-yaml","JSON vs YAML"," — When to choose JSON or YAML for configuration",[792,793,794],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}",{"title":38,"searchDepth":106,"depth":106,"links":796},[797,798,799,800,801,802,803,804,805,806,807],{"id":12,"depth":106,"text":13},{"id":23,"depth":106,"text":24},{"id":83,"depth":106,"text":84},{"id":257,"depth":106,"text":258},{"id":405,"depth":106,"text":406},{"id":529,"depth":106,"text":530},{"id":590,"depth":106,"text":591},{"id":686,"depth":106,"text":687},{"id":725,"depth":106,"text":726},{"id":749,"depth":106,"text":750},{"id":766,"depth":106,"text":767},"2026-05-28","Step-by-step guide to converting between CSV and JSON formats. Covers parsing, delimiters, quoting, and common pitfalls.","md",{"keywords":812},[813,814],"csv-json","csv-json-conversion-guide","\u002Fguides\u002Fcsv-json-conversion-guide",null,{"title":5,"description":809},"guides\u002Fcsv-json-conversion-guide","qUlx9N2IaqkH7v-vWyw9D2L_wPOjkSL9rigFXhVmtjY",1780401329217]