{}JSONLint.app

How to Open JSON Files: A Practical Guide

9 min read
Share:

A .json file is just UTF-8 text, so opening one is rarely the hard part — reading it comfortably and trusting that it's valid is. This guide covers the fastest ways to view JSON across browsers, editors, and the command line, then walks through the encoding, file-association, and "not actually JSON" problems that turn a two-second task into a confusing one.

The Quick Options and Their Tradeoffs

If you just need to look at a JSON file once, pick the tool that's already open.

Drag the file into a browser. Both Chrome and Firefox render local JSON when you drag a .json file onto a tab (or open file:///path/to/file.json). Firefox is the stronger choice here: it ships a built-in JSON viewer with a collapsible tree, a search box, and a "Raw Data" toggle, so you can fold large objects and filter keys without any extension. Chrome shows the JSON as syntax-highlighted text but gives you no tree or search unless you install an extension. The catch with both: very large files (tens of MB) will freeze the tab, and some servers force a download instead of rendering (more on that below).

Open it in VS Code. This is the best default for editing. VS Code highlights JSON, formats it on demand (Shift+Alt+F, or Format Document), and gives you a structural outline in the sidebar — expand it to navigate keys like a table of contents. It also validates against JSON Schema and underlines syntax errors as you type. The downside is the same as browsers: it loads the whole file into memory, so it is the wrong tool for anything approaching a gigabyte.

Paste into an online tree viewer/validator. When you want validation, pretty-printing, and a collapsible tree in one step — and the data isn't sensitive — an online viewer like the one at the top of jsonlint.app is the fastest path. A client-side tool never uploads your data to a server, which matters if the file contains credentials or PII.

Opening JSON on macOS and Linux

The terminal is faster than any GUI for inspecting JSON, and jq is the tool worth installing (brew install jq or apt install jq).

# Pretty-print and syntax-highlight
jq . file.json

# Same thing without jq, using Python's built-in formatter
python3 -m json.tool file.json

# Open in VS Code (the `code` command must be on your PATH)
code file.json

# Just page through the raw bytes — no parsing, works on anything
less file.json

jq . does double duty: it reformats the file and fails loudly if the JSON is invalid, so it doubles as a validator. To pull out a single field, use a filter:

jq '.users[0].email' file.json     # extract one value
jq 'keys' file.json                # list top-level keys
jq '.items | length' file.json     # count array elements

Piping works too, which is handy when JSON arrives from another command:

cat file.json | jq .
curl -s https://api.example.com/data | jq '.results[]'

Opening JSON on Windows (PowerShell)

PowerShell parses JSON natively — no extra install required.

# Parse into a PowerShell object and display it
Get-Content file.json | ConvertFrom-Json

# Pretty-print: parse then re-serialize with indentation
Get-Content -Raw file.json | ConvertFrom-Json | ConvertTo-Json -Depth 100

# If Python is installed, its formatter works the same as on macOS/Linux
Get-Content -Raw file.json | python -m json.tool

Two things to watch on Windows. First, use -Raw whenever you pipe the whole file into a parser; without it, Get-Content streams line by line and can mangle multi-line JSON. Second, ConvertTo-Json defaults to a shallow -Depth of 2 and silently truncates deeper structures — set -Depth 100 to be safe. If you have WSL or Git Bash installed, every jq and python3 command from the previous section works there unchanged.

Large Files: Don't Open Them in an Editor

Once a file passes a few hundred megabytes, double-clicking it in any GUI editor is a mistake — VS Code, Sublime, and browsers all try to load the entire file into RAM and will hang or crash. Stream it instead.

# Peek at the first 5,000 bytes without reading the whole file
head -c 5000 file.json

# Page through it lazily; less only reads what's on screen
less file.json

# Stream a top-level array one element at a time (compact output)
jq -c '.[]' file.json | head -n 20

# Filter a huge array down to matching records before you ever view them
jq -c '.[] | select(.status == "error")' file.json

jq -c '.[]' is the key trick: it emits each array element on its own line as it parses, so memory stays flat regardless of file size. For multi-gigabyte files or repeated processing, reach for a true streaming parser (ijson in Python, jq --stream, or a SAX-style reader). The dedicated guide on parsing large JSON files goes deeper, and the JSON Size Analyzer helps you find which keys are bloating the file before you commit to a strategy.

"I Double-Clicked It and It Just Downloaded / Opened as Raw Text"

This is the most common complaint, and it has two separate causes.

Wrong file association. Your OS opens .json with whatever app is registered for that extension — often a text editor that shows an unformatted wall of text, or nothing useful at all. Fix it with Open With:

  • macOS: right-click the file, Open With → Other…, choose VS Code, and tick Always Open With to make it permanent (or use Get Info → "Open with" → Change All).
  • Windows: right-click → Open with → Choose another app, pick your editor, and check Always use this app.

The server sent it as a download. When you click a JSON link on a website and the browser downloads it instead of displaying it, the server is sending a Content-Type: application/json (or application/octet-stream) header, sometimes with Content-Disposition: attachment. That tells the browser "this is a file to save, not a page to render." There's nothing to fix on your end — it's server behavior. Just download the file and open it locally with one of the methods above, or fetch and view it in the terminal in one step:

curl -s https://example.com/data.json | jq .

"This Isn't Valid JSON" — When It's Actually Something Else

If a parser rejects a file that looks like JSON, it's usually one of these near-relatives. Diagnose before you despair.

NDJSON / JSON Lines. One JSON object per line, with no enclosing array and no commas between lines. jq . chokes on the second object. Process it line by line instead:

jq -c . file.ndjson           # jq handles a stream of objects fine
# Wrap it into a real array if you need one:
jq -s . file.ndjson > array.json

JSONP. The content is wrapped in a function call: callback({"a":1});. That's JavaScript, not JSON. Strip the wrapper before parsing:

sed -E 's/^[^(]+\((.*)\);?$/\1/' file.jsonp | jq .

JSON5 or comments. Trailing commas, single quotes, // comments, or unquoted keys mean it's JSON5 (common in config files like tsconfig.json). Standard parsers reject it — use a JSON5-aware tool, or strip the extras manually.

A UTF-8 BOM. A byte-order mark (the bytes EF BB BF) at the very start of the file makes strict parsers report an error on "the first character." Detect and remove it:

file file.json                          # may say "UTF-8 (with BOM)"
sed -i '1s/^\xEF\xBB\xBF//' file.json   # strip the BOM in place

UTF-16 from a Windows export. Tools like Excel or PowerShell's Out-File sometimes write UTF-16, which most JSON libraries can't read. The file command reveals the encoding; iconv converts it:

file file.json                                   # e.g. "Little-endian UTF-16 Unicode text"
iconv -f UTF-16 -t UTF-8 file.json > utf8.json   # convert to UTF-8
jq . utf8.json                                   # now it parses

When you've ruled out encoding and it's a genuine syntax mistake — a missing comma or bracket — the JSON syntax error guide covers how to read parser messages and locate the exact position.

Reading and Parsing a JSON File in Code

When opening the file is part of a program, here's the canonical pattern in three languages.

// Node.js — async read, then parse
import { readFile } from "node:fs/promises";

const text = await readFile("file.json", "utf8");
const data = JSON.parse(text);
console.log(data.users.length);
import json

with open("file.json", encoding="utf-8") as f:
    data = json.load(f)   # parses straight from the file handle

print(len(data["users"]))
package main

import (
	"encoding/json"
	"fmt"
	"os"
)

func main() {
	raw, err := os.ReadFile("file.json")
	if err != nil {
		panic(err)
	}
	var data map[string]any
	if err := json.Unmarshal(raw, &data); err != nil {
		panic(err)
	}
	fmt.Println(len(data))
}

In every case, read the file as UTF-8 and let the standard library parse it; don't try to split or regex JSON by hand. For Python specifics — including streaming large files and handling dates — see working with JSON in Python. And once you can open a file reliably, a quick read on why formatting JSON matters explains why pretty-printing before you commit data to version control saves real time in diffs and reviews.

Tools

  • JSON Validator & Tree Viewer — Paste a file to validate and explore it in a collapsible tree, entirely in your browser.
  • JSON Tree — Navigate deeply nested JSON visually instead of scrolling through raw text.
  • JSON to Table — Turn arrays of objects into a sortable table that's far easier to scan than raw JSON.
  • JSON Size Analyzer — See which keys and arrays are inflating a large file before you decide how to open it.

Learn More

Related Articles