Skip to content
Back to Learn
·5 min read

Top JSON Debugging Tools Every Developer Should Know

Debugging JSON issues is a daily task for most developers. Whether you are troubleshooting a malformed API response, fixing a serialization error, or tracking down a data transformation bug, having the right tools and techniques makes the difference between minutes and hours of debugging. This guide covers browser developer tools, online validators, command-line utilities, editor integrations, and logging strategies for JSON debugging. Use our JSON Validator for quick syntax checks and JSON Formatter for readability.

Common JSON Debugging Scenarios

SymptomLikely CauseTool to Use
API returns 400 Bad RequestMalformed JSON in request bodyJSON Validator
Unexpected data in UIWrong JSON path or type mismatchJSON Tree Viewer
JSON.parse() throws SyntaxErrorTrailing comma, single quotes, unquoted keysJSON Fixer
Large JSON file is slowUnnecessary nesting or repeated dataJSON Minifier
JSON circular reference errorObject references itself during serializationCustom replacer function
Numbers lose precisionJavaScript Number.MAX_SAFE_INTEGER exceededJSON with bigint as string
Date type lost after parsingJSON has no Date typeReviver function or ISO strings

Browser DevTools for JSON Debugging

Network Tab

The browser's Network tab is the most powerful JSON debugging tool. Key features:

  • View raw JSON request and response bodies
  • Preview tab shows JSON with collapsible tree view
  • Response tab shows raw text
  • Headers tab shows content-type and other metadata
  • Copy as cURL to reproduce requests
  • Block request URLs to test error handling

Console Shortcuts

// Copy JSON object as string
copy(responseData);  // Copies JSON string to clipboard

// Format JSON in console
console.log(JSON.stringify(data, null, 2));

// Table view for arrays
console.table(usersArray);

// Group and trace
console.group('API Response');
console.log('Status:', status);
console.log('Data:', data);
console.groupEnd();

JSON Fixer for Common Errors

One of the most useful debugging tools is a JSON fixer that can repair common issues. Our JSON Fixer automatically fixes:

IssueBeforeAfter
Single quotes{'name': 'Alice'}{"name": "Alice"}
Unquoted keys{name: "Alice"}{"name": "Alice"}
Trailing commas[1, 2, 3,][1, 2, 3]
Missing quotes{"value": null} already OKFixes various quote issues
Comment lines// commentStrips or preserves

Command-Line JSON Debugging

# Pretty print from pipe
curl https://api.example.com/data | python3 -m json.tool

# Validate JSON file
echo '{"key": "value"}' | python3 -c "import json,sys; json.load(sys.stdin)"

# jq for querying and formatting
curl https://api.example.com/data | jq '.'
curl https://api.example.com/data | jq '.users[] | {name, email}'

# jq with color output
curl https://api.example.com/data | jq -C '.'

# Count items in JSON array
curl https://api.example.com/data | jq '.items | length'

Debugging JSON.parse() Errors

function safeJSONParse(str) {
  try {
    return { data: JSON.parse(str), error: null };
  } catch (e) {
    // Extract position information
    const posMatch = e.message.match(/positions+(d+)/);
    const position = posMatch ? parseInt(posMatch[1]) : -1;

    // Show context around the error
    const start = Math.max(0, position - 20);
    const end = Math.min(str.length, position + 20);
    const context = str.substring(start, end);

    return {
      data: null,
      error: {
        message: e.message,
        position: position,
        context: context,
        pointer: ' '.repeat(Math.min(20, position)) + '^'
      }
    };
  }
}

// Usage
const result = safeJSONParse(malformedJson);
if (result.error) {
  console.error('JSON Error at', result.error.position);
  console.error('Context:', result.error.context);
  console.error('         ' + result.error.pointer);
}

Logging JSON for Debugging

// Structured JSON logging
function debugJSON(label, data, options = {}) {
  const { depth = 3, colors = true } = options;
  const entry = {
    timestamp: new Date().toISOString(),
    label: label,
    data: data
  };
  console.log(JSON.stringify(entry, null, 2));
}

// Log with circular reference handling
function safeStringify(obj, indent = 2) {
  const seen = new WeakSet();
  return JSON.stringify(obj, (key, value) => {
    if (typeof value === 'object' && value !== null) {
      if (seen.has(value)) return '[Circular]';
      seen.add(value);
    }
    return value;
  }, indent);
}

Editor Integration

  • VS Code — Built-in JSON validation with squiggly underlines, schema-driven IntelliSense via json.schemas setting, and JSON language features
  • WebStorm/IntelliJ — JSON validation, formatting, structure view, and schema support
  • Sublime Text — Pretty JSON plugin, syntax highlighting, validation
  • Vim:%!python3 -m json.tool for formatting, ALE for linting

Debugging Workflow

  1. Copy the problematic JSON string
  2. Paste into JSON Validator for syntax check
  3. Use JSON Fixer to repair common issues
  4. Format with JSON Formatter for readability
  5. Explore the structure with JSON Tree Viewer
  6. Compare with expected output using JSON Compare

Next Steps

Validate your JSON with JSON Validator. Fix malformed JSON with JSON Fixer. Format and explore with JSON Formatter and JSON Tree Viewer. Compare versions with JSON Compare.