Β· By DevToolHub Team

How to Read and Debug JSON: Tree View vs Raw Text

You make an API call and get back 500 lines of minified JSON. Or you open a config file with deeply nested objects five levels deep. How do you make sense of it?

Reading and debugging JSON is a daily task for most developers. Whether you are inspecting API responses, tracking down a missing field in a config file, or validating data before sending it to a database, you need the right approach. There are two fundamental methods: working with raw text (using a JSON Formatter or jq) and using a tree view for visual exploration. Each has strengths, and knowing when to use which will make you significantly faster at debugging JSON data issues.

The Problem with Raw JSON

Here’s a typical API response, minified as most APIs deliver it:

{"users":[{"id":1,"name":"Alice","address":{"street":"123 Main St","city":"Springfield","state":"IL","zip":"62701"},"roles":["admin","editor"],"preferences":{"theme":"dark","notifications":{"email":true,"sms":false,"push":true}}},{"id":2,"name":"Bob","address":{"street":"456 Oak Ave","city":"Portland","state":"OR","zip":"97201"},"roles":["viewer"],"preferences":{"theme":"light","notifications":{"email":false,"sms":false,"push":false}}}]}

Good luck finding Bob’s push notification setting in there. Even after formatting with proper indentation, deeply nested JSON is hard to navigate visually β€” you’re constantly counting brace levels and matching opening/closing brackets.

Approach 1: Raw Text + Formatting

The simplest improvement is to format (pretty-print) the JSON with proper indentation. This works well for:

  • Small to medium documents (under ~200 lines)
  • Flat or shallow structures (1-2 levels of nesting)
  • When you need to edit the JSON (tree views are usually read-only)
  • Quick validation β€” is this even valid JSON?

Tools for this approach:

  • jq '.' in the terminal β€” the Swiss army knife of JSON processing
  • python -m json.tool β€” no installation needed if Python is available
  • Your IDE’s built-in formatter (VS Code: Shift+Alt+F)
  • JSON.stringify(data, null, 2) in a browser console

Pro tip with jq: You can filter and extract specific paths:

# Get just Bob's notification settings
cat data.json | jq '.users[1].preferences.notifications'

# Get all user names
cat data.json | jq '.users[].name'

# Find users with admin role
cat data.json | jq '.users[] | select(.roles[] == "admin")'

Approach 2: Tree View

A tree view renders JSON as a collapsible, hierarchical structure β€” like a file explorer for your data. Each key-value pair is a node that you can expand or collapse.

This works best for:

  • Large documents (1000+ lines when formatted)
  • Deeply nested structures (3+ levels)
  • Exploring unfamiliar data β€” you don’t know the structure yet
  • Finding specific values β€” visual search through collapse/expand

With a tree view, finding Bob’s push notification setting becomes trivial: expand users β†’ expand [1] β†’ expand preferences β†’ expand notifications β†’ see push: false. No bracket counting needed.

What to Look for in a Tree View

A good JSON tree viewer shows:

  • Color-coded types β€” strings, numbers, booleans, and null should be visually distinct
  • Collapse/expand β€” with keyboard shortcuts, not just mouse clicks
  • Node counts β€” {5} next to objects (5 keys) and [10] next to arrays (10 items)
  • Path display β€” showing the full path like users[1].preferences.notifications.push
  • Search β€” find nodes by key name or value

When to Use Which

ScenarioBest approach
Quick API response checkRaw text + format
Editing a config fileRaw text in IDE
Exploring a new API’s response shapeTree view
Debugging a deeply nested bugTree view
Processing JSON programmaticallyjq or code
Validating JSON syntaxValidator tool
Comparing two JSON documentsDiff tool

Common JSON Parsing Errors

These are the mistakes that catch developers most often. JSON syntax is strict β€” unlike JavaScript object literals, there is no room for shortcuts.

Trailing Commas

// INVALID β€” trailing comma after "banana"
{
  "fruits": ["apple", "banana",]
}

JavaScript allows trailing commas in objects and arrays, but JSON does not. Remove the last comma or use a linter that catches this.

Single Quotes

// INVALID β€” strings must use double quotes
{'name': 'Alice'}

// VALID
{"name": "Alice"}

JSON requires double quotes for both keys and string values. This is defined in the JSON specification (ECMA-404).

Unquoted Keys

// INVALID β€” keys must be quoted
{name: "Alice"}

// VALID
{"name": "Alice"}

Comments

// INVALID β€” no comments in JSON
{
  "port": 8080,  // server port
  "debug": true  /* enable logging */
}

If you need comments in config files, consider YAML (which supports # comments), JSONC, JSON5, or TOML.

Special Values

// INVALID β€” NaN, Infinity, and undefined are not valid JSON
{"value": NaN, "max": Infinity, "data": undefined}

// VALID alternatives
{"value": null, "max": 1.7976931348623157e+308, "data": null}

Encoding Issues

If your JSON contains non-ASCII characters and parsing fails, check the encoding. JSON must be UTF-8, UTF-16, or UTF-32, with UTF-8 strongly recommended. Files saved in Latin-1 or Windows-1252 encoding will break on characters like Γ© or Γ±.

Debugging Tips

Start with validation. Before trying to read JSON, make sure it’s actually valid. A missing comma or extra bracket can make the whole document unparseable. Use a JSON Validator to catch syntax errors with clear error messages.

Pretty-print, then search. If you know the key name you’re looking for, format the JSON and use your text editor’s search (Ctrl+F). This is faster than manually navigating a tree for known paths.

Use the browser console for API debugging. When debugging API responses:

fetch('/api/users')
  .then(r => r.json())
  .then(data => {
    console.log(data);             // Chrome shows an interactive tree
    console.table(data.users);      // Table view for arrays of objects
  });

Chrome DevTools and Firefox DevTools both show JSON as interactive trees in the console β€” often the fastest way to explore API responses during development.

Convert to YAML for readability. For deeply nested config-like JSON, temporarily converting to YAML can make the structure clearer thanks to YAML’s indentation-based syntax. Use our JSON to YAML Converter for a quick view.

Export to CSV for tabular data. If you’re dealing with arrays of flat objects (like API results), converting JSON to CSV and opening in a spreadsheet can be faster than reading nested structures.

Try It Yourself

Use our JSON Tree Viewer to paste any JSON and explore it as an interactive tree β€” with color-coded types, node counts, and expand/collapse at every level.

Further Reading

  • json.org β€” The official JSON specification and syntax diagrams
  • RFC 8259 β€” The JSON Data Interchange Format (IETF standard)
  • jq Manual β€” Complete reference for the jq command-line JSON processor
  • MDN: JSON.parse() β€” JavaScript JSON parsing reference
  • MDN: JSON.stringify() β€” JavaScript JSON serialization reference

FAQ

What is the fastest way to pretty-print a JSON file from the command line?
Use jq: cat file.json | jq '.' β€” it formats with colors and 2-space indentation by default. If jq isn't installed, Python works everywhere: python -m json.tool file.json. For Node.js environments, use: node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync(0,'utf8')),null,2))" < file.json.
How do I find a specific key in a large JSON file?
With jq, use recursive descent: jq '.. | .yourKey? // empty' file.json β€” this searches every level of nesting. In a tree viewer, use the search/filter feature to find nodes by key name. In a text editor, pretty-print first, then Ctrl+F for the key name.
Why does my JSON file fail to parse with no clear error?
Common silent issues include: trailing commas after the last item in an array or object (not allowed in JSON), single quotes instead of double quotes around strings, unquoted keys, comments (// or /* */), and NaN or Infinity values. Use a JSON validator to get a precise error with line and column numbers.
What is the difference between JSON.parse() and JSON.stringify()?
JSON.parse() converts a JSON string into a JavaScript object. JSON.stringify() does the reverse β€” converts a JavaScript object into a JSON string. They are inverses: JSON.parse(JSON.stringify(obj)) creates a deep clone (losing functions, undefined, and special types like Date objects).
Can JSON contain comments?
No. The JSON specification (RFC 8259 / ECMA-404) does not allow comments. If you need comments in configuration files, consider JSONC (JSON with Comments, supported by VS Code and TypeScript), JSON5, YAML, or TOML. To strip comments from JSONC before parsing, tools like strip-json-comments can help.
What is the best JSON viewer for large files?
For files under 10 MB, browser-based tree viewers (like our JSON Tree Viewer) work well. For larger files, use jq on the command line β€” it streams data without loading everything into memory. VS Code can handle files up to ~50 MB with the built-in JSON formatter. For truly massive files (100 MB+), use specialized tools like fx (terminal JSON viewer) or process with streaming parsers in Python (ijson) or Node.js (stream-json).
json debugging api tools productivity

Related Tools

Related Articles