Json To Csv LogoJson To Csv

How Do I Convert JSON to CSV in VS Code? 4 Ways, From Click to One Keypress (2026 Guide)

VS Code has no built-in JSON-to-CSV command, but it gives you four honest routes: a one-click extension, the integrated terminal with jq or Python, a saved tasks.json task, or an online converter when you want zero setup. Here is each one, tested on real nested data.

Updated: 2026-10-1510 min read

First, the honest framing: VS Code is an editor, not a converter

If you have searched the menus, you have not missed anything. VS Code has no Convert to CSV command, no Export menu for JSON, and no built-in way to turn a .json file into a .csv file. That is not an oversight, VS Code is a code editor, and format conversion is the kind of job it delegates to extensions, the terminal, and tasks. Once you accept that, the question stops being “where is the button?” and becomes “which of the four routes fits this file?”

The four routes, in brief: an extension for one-click conversion inside the editor; the integrated terminal for full control with jq or Python; a tasks.json task for conversions you repeat every week; and an online converter for one-off files where you want zero setup. Each one is genuinely best at one thing, and each one has a failure mode the others avoid. This guide covers all four, with the exact commands and the exact outputs they produced on a real nested test file, a three-order JSON document with nested customer objects, item lists, and a null total.

Route 1: the JSON2CSV extension (fastest for one file)

For a single file you want converted right now, an extension is the least-effort route. The one to install is JSON2CSV by khaeransori, on the Visual Studio Code Marketplace. Its README documents the workflow plainly: install it, open a JSON file, open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS), type Convert JSON to CSV, and the converted CSV opens in a new editor tab, where you save it with Ctrl+S. It also converts the other direction, CSV to JSON, from the same palette.

Installation takes under a minute: open the Extensions view with Ctrl+Shift+X, search for json2csv, and click Install on the entry published by khaeransori. Two habits keep extension installs safe in general, and they apply here as much as anywhere: check the publisher name matches before you click Install (copycat extensions with similar names exist for popular tools), and glance at the download count and recent update date. An extension runs code on your machine with access to your files, so a moment of publisher-checking is worth more than any feature list.

Two alternatives exist if JSON2CSV does not fit. DataMorph (listed as Data Format Converter) converts between CSV, JSON, and Excel from the right-click context menu or the Command Palette, and advertises batch conversion of several files at once plus smart flattening of nested JSON. Algae Data is a lighter option: open a JSON file, run Algae: JSON to CSV from the Command Palette, and the result opens in a new editor window. All three are real Marketplace extensions with public listings; pick the one whose feature list matches your files, not the one with the loudest description.

The honest limitation of the extension route: you are trusting a third-party tool with your data, and its flattening choices are its own. If your JSON is deeply nested or your column order matters, the terminal routes below give you explicit control over both, which is why developers who convert JSON weekly usually end up on Route 2 or 3.

Route 2: the integrated terminal, jq for flat data, Python for nested data

The integrated terminal is VS Code's superpower for this job: press Ctrl+` (the backtick key) and you have a full shell inside the editor, in your project folder, with your file open beside it. No window-switching, no uploads, and every command below is re-runnable. Two tools cover nearly every file: jq for quick flat conversions, and Python for anything nested.

Start with jq, the JSON command-line processor. If your JSON is an array of flat objects, no nested objects, no arrays inside rows, one command does the whole conversion. It collects every key across all rows as the header, then emits each row as CSV:

jq: flat JSON array to CSV (verified)
jq -r '(map(keys) | add | unique) as $cols | $cols, (.[] | [.[$cols[]]] | @csv)' flat.json > flat.csv

On a flat test file of two orders (id, name, total), that command produced exactly this: a header row id,name,total followed by 1,"Ana",24.5 and 2,"Bo",9.0. Clean, correct, and instant. But try the same command on nested data and jq stops you honestly: on our nested three-order test file it errored with “object is not valid in a csv row,” because a nested object like customer has no single CSV cell to live in. That error is jq telling you the truth: flat tools need flat rows.

Route 2: the integrated terminal, jq for flat data, Python for nested data (continued)

For nested JSON, jq still works if you name the columns explicitly. This recipe pulls the fields you want by path, joins the items list into one cell with "; ", and writes the CSV:

jq: nested JSON with explicit columns (verified)
jq -r '["id","name","city","items","total"], (.[] | [.id, .customer.name, .customer.city, (.items | join("; ")), .total]) | @csv' orders.json > orders.csv

Run against the nested test file, that produced a header of "id","name","city","items","total" and three rows, including 1,"Ana","Oslo","book; pen",24.5 and 3,"Cy","Trondheim","", for the order with an empty items list and a null total. Note two jq behaviors worth knowing: @csv quotes every string (correct, if noisy), and null becomes an empty field only when it lands in a string context, the third row's empty items cell came from join on an empty list, while the null total printed as an empty field at the end of the row. Explicit columns mean explicit control: you decide the column order, the nesting paths, and what each list becomes.

Route 2: the integrated terminal, jq for flat data, Python for nested data (continued)

When naming every column by hand gets tedious, Python is the better tool. Save this small script as convert.py in your project, it flattens nested objects into dot-notation columns (customer.name), joins plain lists with "; ", turns null into an empty cell, and writes a proper CSV with the standard csv module handling quoting for you:

convert.py, flattening JSON-to-CSV script (verified)
import json, csv, sys

def flatten(obj, prefix=""):
    out = {}
    if isinstance(obj, dict):
        for k, v in obj.items():
            key = f"{prefix}.{k}" if prefix else k
            out.update(flatten(v, key))
    elif isinstance(obj, list):
        out[prefix] = "; ".join(str(x) for x in obj if not isinstance(x, (dict, list))) if obj else ""
        for i, v in enumerate(obj):
            if isinstance(v, (dict, list)):
                out.update(flatten(v, f"{prefix}[{i}]"))
    else:
        out[prefix] = "" if obj is None else obj
    return out

rows = json.load(open(sys.argv[1]))
if isinstance(rows, dict):
    rows = [rows]
flat = [flatten(r) for r in rows]
cols = sorted({k for r in flat for k in r})
with open(sys.argv[2], "w", newline="", encoding="utf-8") as f:
    w = csv.DictWriter(f, fieldnames=cols)
    w.writeheader()
    w.writerows(flat)
print(f"wrote {sys.argv[2]}: {len(flat)} rows, {len(cols)} columns")

Run it from the integrated terminal with python3 convert.py orders.json orders.csv. On the same nested test file it printed “wrote orders.csv: 3 rows, 5 columns” and produced customer.city,customer.name,id,items,total as the header, with rows Oslo,Ana,1,book; pen,24.5 / Bergen,Bo,2,mug,9.0 / Trondheim,Cy,3,,, the null total and empty items list both landing as empty cells, exactly as the flattening rules promise. The script handles the two shapes people actually hit: a top-level array (the normal case) and a single top-level object (wrapped into a one-row table). Both jq recipes and this script were run on the build machine before publishing, and the outputs above are their real outputs, not illustrations.

Route 3: save it as a task, one keypress, every time

If you convert JSON files more than once a month, stop retyping commands and save the conversion as a VS Code task. A task is a named command in .vscode/tasks.json, runnable from Terminal → Run Task or with the keyboard shortcut Ctrl+Shift+B. It turns the Python route above into a one-keypress operation on whatever file you have open.

Create .vscode/tasks.json in your project with this content (the file was checked to parse as valid JSON before publishing):

.vscode/tasks.json, convert the open file (verified to parse)
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "JSON to CSV: convert current file",
      "type": "shell",
      "command": "python3 ${workspaceFolder}/convert.py ${file} ${fileDirname}/${fileBasenameNoExtension}.csv",
      "problemMatcher": []
    }
  ]
}

How it works: ${file} is the file open in your active editor, ${fileDirname} is its folder, and ${fileBasenameNoExtension} is its name without .json, so with orders.json open, the task runs python3 convert.py on it and writes orders.csv next to it. Open any JSON file, press Ctrl+Shift+B, pick the task, and the CSV appears beside the source. The same pattern works for the jq recipes: replace the command with the jq line and ${file} as input. One caution: tasks run shell commands with your user permissions, so only add tasks from sources you trust, the same rule as extensions, applied to configuration.

The task route is also where the Python script earns its keep over jq: one script plus one task handles flat files, nested files, single objects, and arrays alike, with no per-file command editing. If you convert exports from the same API every week, this is the route that pays off.

Route 4: when to skip VS Code entirely and use an online converter

There are three situations where leaving the editor is the right call. First, a one-off file on a machine where you cannot install extensions or do not have jq or Python handy, a borrowed laptop, a locked-down work machine, a Chromebook. Second, JSON whose nesting is awkward enough that writing explicit jq paths feels like work: an online converter with a flattening toggle turns the whole tree into columns in one click, and you can see the preview before downloading. Third, sharing: if the CSV is for a colleague who does not use VS Code, converting in the browser and sending them the finished file is simpler than explaining your toolchain.

The online route on this site runs entirely in your browser, paste JSON or upload the file, the conversion happens client-side with no upload to a server, nested data flattens to dot-notation columns, and the download is plain UTF-8. For a VS Code user the honest comparison is: the online converter trades the repeatability of a task for zero setup and an instant preview. Use the editor routes when the conversion repeats; use the browser route when it does not.

Inspecting the result inside VS Code (and why the raw text is the truth)

Whatever route you take, inspect the CSV in VS Code before you trust it. VS Code shows you the raw file, the actual commas, quotes, and line breaks, while a spreadsheet shows you its interpretation of them. If the two disagree, the raw text is the truth and the spreadsheet is guessing. Two extensions make inspection easier: Edit CSV opens a CSV as an editable spreadsheet-style table inside the editor, and Rainbow CSV colors each column a different color so misaligned rows jump out visually.

The most common “my CSV is broken” report is a file that opens in Excel as one long column. Nine times out of ten the file is fine: Excel guessed the wrong delimiter (often a semicolon file opened as comma) or the wrong encoding. Open the file in VS Code first, if the commas and quotes look right in the raw text, the file is right, and the fix is on the import side (Excel: Data → From Text/CSV, pick the delimiter and 65001 UTF-8). The status bar at the bottom of VS Code also shows the file's encoding; if a file looks mangled, use File → Save with Encoding → UTF-8 to normalize it, and Save with Encoding → UTF-8 with BOM only if a specific Windows tool demands a BOM.

Troubleshooting: the four errors VS Code users actually hit

Invalid JSON, flagged before you convert. If the file has red squiggles or the Problems panel lists errors, fix those first, no converter accepts malformed JSON. Two VS Code-specific traps: settings-style files allow comments and trailing commas (that is JSONC, not JSON), and a stray trailing comma after the last element is the single most common syntax error. Strip comments and trailing commas before converting; VS Code's own JSON language service will usually point at the exact line.

A single object instead of an array. APIs often return {"data": [...], "total": 2} or a lone {...} rather than a bare array. The Python script above handles a lone object by wrapping it into one row, and for a wrapper object you want the rows inside it: extract the array first (in jq, .data | ...; in Python, rows = json.load(...)["data"]), or the converter will give you one row with the whole array stringified into a cell.

Nested data that “disappears.” Flattening always makes choices: lists of objects have no single-cell representation, and the Python script above joins only plain-value lists, recursing into object lists with indexed keys (items[0].name). If your lists contain objects and the output looks wrong, that is the flattening rule showing, not data loss, decide per column whether you want the list joined, expanded into rows, or dropped, and say so in the script rather than accepting a default silently.

Huge files. An extension converting a 200 MB JSON file inside the editor can hang the UI; the terminal routes stream better, and jq in particular handles large files without loading a preview. If VS Code feels slow, that is the signal to use the terminal: jq or Python on the command line, with the editor just showing the result.

Which route should you pick?

One file, right now, no setup: the JSON2CSV extension, install, Command Palette, save the new tab. Files you convert every week: the Python script plus a tasks.json task, one keypress, same result every time. A quick flat file and you like the terminal: the jq one-liner. A one-off file on a locked-down machine, or awkward nesting you want to preview before committing: the online converter. None of these is “the” VS Code way, because VS Code deliberately has no single built-in way, the editor gives you the pieces, and the right combination is the one that matches how often you convert and how nested your data is.

Open the free JSON to CSV converter

Related guides

Frequently asked questions

How do I convert JSON to CSV in VS Code?

VS Code has no built-in converter, so add one of four routes: install the JSON2CSV extension and run Convert JSON to CSV from the Command Palette; use the integrated terminal with jq (flat data) or a Python script (nested data); save the conversion as a tasks.json task for one-keypress repeats; or paste the JSON into a free online converter for a one-off file with zero setup.

What is the best VS Code extension for JSON to CSV?

JSON2CSV by khaeransori is the most direct: install it from the Extensions view, open your JSON file, run Convert JSON to CSV from the Command Palette, and the CSV opens in a new tab. DataMorph (Data Format Converter) adds Excel conversion and batch processing; Algae Data is a lighter alternative. Always verify the publisher name before installing any extension.

Can I convert JSON to CSV in VS Code without an extension?

Yes, use the integrated terminal (Ctrl+`). For flat JSON arrays: jq -r '(map(keys) | add | unique) as $cols | $cols, (.[] | [.[$cols[]]] | @csv)' file.json > file.csv. For nested JSON, use jq with explicit column paths or a small Python script that flattens nested objects into dot-notation columns. Both routes were tested on real data for this guide.

Why does jq fail with “object is not valid in a csv row”?

Because a row contains a nested object or array, and CSV rows can only hold flat values. The generic jq @csv recipe only works on flat rows. Fix it by naming columns explicitly (jq -r '["id","name",...], (.[] | [.id, .customer.name, ...]) | @csv') or by flattening first with a Python script that turns nested objects into dot-notation columns.

How do I automate JSON to CSV conversion in VS Code?

Save a task in .vscode/tasks.json that runs your conversion command on the open file, for example python3 ${workspaceFolder}/convert.py ${file} ${fileDirname}/${fileBasenameNoExtension}.csv, then press Ctrl+Shift+B (Terminal → Run Task) with any JSON file open. The CSV is written next to the source file every time, with no retyping.

Why does my CSV from VS Code open as one column in Excel?

Usually the file is fine and Excel guessed the wrong delimiter or encoding. Check the raw text in VS Code first: if the commas and quotes look right there, the file is right. Re-import in Excel via Data → From Text/CSV, choose the correct delimiter and 65001 (UTF-8) encoding, instead of double-clicking the file.

Can VS Code convert JSONC or JSON with comments to CSV?

Not directly, comments and trailing commas are JSONC, not JSON, and no converter accepts them. Strip comments and trailing commas first (VS Code's Problems panel flags the exact lines), then convert the clean JSON. The same applies to settings files and .code-workspace files, which are JSONC by design.

One-off file? Convert it in the browser, no extension needed

Paste JSON or upload a file: nested data flattens to clean columns, delimiters and quoting are automatic, and the download is plain UTF-8. Free, no sign-up, runs entirely in your browser.

Open the JSON to CSV converter
All guides