Developer

Understanding JSON: A Practical Guide for Developers

ToolOrbit Engineering 2 min readUpdated
Understanding JSON: A Practical Guide for Developers

JSON (JavaScript Object Notation) is the lingua franca of the modern web. It is how browsers talk to servers, how APIs return data, and how configuration is stored across countless tools. Despite its simplicity, small mistakes cause big headaches.

The building blocks

JSON has just six value types: strings, numbers, booleans, null, arrays and objects. Objects are unordered key/value pairs wrapped in braces; arrays are ordered lists wrapped in brackets.

{
  "name": "Ada",
  "active": true,
  "skills": ["math", "code"],
  "manager": null
}

The mistakes that break parsers

  • Trailing commas — valid in JavaScript, invalid in JSON.
  • Single quotes — JSON strings must use double quotes.
  • Unquoted keys — every key must be a quoted string.
  • Comments — JSON has no comment syntax.
Tip: paste suspicious JSON into the JSON Formatter to see the exact line and reason a parser rejects it.

Formatting for humans and machines

Pretty-print JSON when you are reading it, and minify it when you are shipping it. Indentation makes structure obvious during debugging, while minification removes whitespace to shrink payloads in production.

When JSON is not the right format

JSON wins for APIs, configuration and anything nested. But it is not the best tool for every job: CSV is lighter for flat tabular exports, YAML is friendlier for hand-edited config you want commented, and XML is still expected by feeds and legacy SOAP services. Choosing by data shape — not by habit — keeps every format doing what it is good at.

Parsing safely in JavaScript

try {
  const data = JSON.parse(input)
  // …use data
} catch (err) {
  console.error(err.message) // line & column of the parse error
}

JSON.parse throws on the first syntax problem and its message names the offending position — which is exactly why a formatter that pinpoints the line is so useful when a payload arrives from a third party.

Still stuck after fixing every comma? Past the JSON into the JSON Formatter: it validates and points at the exact line and reason the parser rejects it.

JSON in the API lifecycle

APIs mostly speak JSON, and the format your tooling mistrusts will cost you debugging cycles. A response that “looks fine” but fails downstream usually fails for three reasons: a trailing comma, a missing comma between objects, or an unexpected nesting depth in array-of-objects data. Validating the payload before it reaches the consumer, and formatting before you read it, keeps every layer of the pipeline working from the same, verified document rather than from uncertain text.

  • Formatted JSON is the debugging format; minified JSON is the transport format.
  • Keep payloads validated — a parser error deep in a microservice is the most expensive kind.
  • Nested applications often have cleaner surface if you break them out — but that is an API design call, not a format one.

Tools mentioned

More reading

View all guides
What Is Base64? How Encoding Works and Common Mistakes
Developer

What Is Base64? How Encoding Works and Common Mistakes

What Base64 encoding actually does, where it is used, and the mistakes that cause broken or oversized output.

2 min readUpdated
encodeURI vs encodeURIComponent: Which One to Use
Developer

encodeURI vs encodeURIComponent: Which One to Use

How percent-encoding works, the difference between encoding a whole URL and a single component, and the mistakes that break links.

2 min readUpdated
What Is a UUID? Version 4 vs Version 7 Explained
Developer

What Is a UUID? Version 4 vs Version 7 Explained

What a UUID looks like, why version 4 is the safe default, when version 7 is better, and best practices for IDs.

2 min readUpdated
How SHA-256 and SHA-512 Hashes Work: Hashing vs Encryption
Developer

How SHA-256 and SHA-512 Hashes Work: Hashing vs Encryption

What a hash function does, how to choose between SHA-256 and SHA-512, and why hashing is not encryption.

2 min readUpdated
What Is a JWT? Header, Payload and Signature Explained
Developer

What Is a JWT? Header, Payload and Signature Explained

A JSON Web Token has three parts. Learn what the header, payload and signature contain, how to read the claims, and why decoding is not verifying.

2 min readUpdated
What Is HTML Encoding? Entities & Escaping Explained
Developer

What Is HTML Encoding? Entities & Escaping Explained

Learn how HTML encoding works, why escaping prevents XSS and layout breaks, and how to encode and decode named, decimal, and hex entities.

2 min readUpdated
Unix Time Explained: Seconds, Milliseconds and Time Zones
Developer

Unix Time Explained: Seconds, Milliseconds and Time Zones

What a Unix timestamp is, how to tell seconds from milliseconds, how time zones come into it, and the values worth recognising.

2 min readUpdated
Binary, Octal, Decimal and Hex: How Number Bases Work
Developer

Binary, Octal, Decimal and Hex: How Number Bases Work

How positional number bases work, why very large values need exact arithmetic, and the hex and binary values you meet every day.

2 min readUpdated