About Me

header ads
Advertisement

What Is JSON and How to Format It

What Is JSON and How to Format It

JSON (JavaScript Object Notation) is a lightweight text format for storing and sending data. It is used by most web APIs, configuration files, and apps because it is easy for humans to read and easy for programs to parse.

A simple example

json
{
  "name": "Ayesha",
  "age": 28,
  "skills": ["design", "writing"],
  "active": true,
  "address": null
}

The building blocks

  • Objects: key-value pairs inside curly braces {}
  • Arrays: ordered lists inside square brackets []
  • Values: strings, numbers, true, false, or null

Rules that trip people up

  1. Keys must be in double quotes. Single quotes are not valid JSON.
  2. No trailing commas after the last item.
  3. No comments are allowed in standard JSON.
  4. Strings need double quotes too, and special characters must be escaped.

A common error, fixed

Invalid:

json
{
  'name': 'Ayesha',
  "age": 28,
}

Valid:

json
{
  "name": "Ayesha",
  "age": 28
}

Why formatting matters

API responses often arrive as one long unreadable line. Formatting (also called beautifying or pretty-printing) adds line breaks and indentation so you can see the structure and spot mistakes quickly. The opposite, minifying, strips whitespace to make the file smaller for production.

Format and validate in seconds

Paste your data into a JSON formatter to beautify, minify, and check for syntax errors. If a response contains encoded text, a Base64 converter may help, and a diff checker is useful for comparing two versions of a file.

Good habits

  1. Use consistent indentation, typically 2 or 4 spaces.
  2. Validate JSON before sending it to an API.
  3. Avoid pasting sensitive data, such as API keys or customer records, into tools you do not trust.
  4. Keep key names consistent, for example always firstName or always first_name.