What Is JSON? Reading an API Response

Follow a small API response from raw text to useful values, and understand how JSON differs from a JavaScript object.

JSON stands for JavaScript Object Notation. It is a text format used to exchange structured data between programs. Despite its name, you can read and produce JSON in many programming languages.

Read a response as a set of values

{
  "id": 42,
  "name": "Sample project",
  "tags": ["api", "public"],
  "archived": false,
  "owner": null
}

The outer braces describe an object. Its names identify values: id is a number, name is a string, and tags is an array. false is a boolean; it differs from the string "false". Here, null represents an explicitly empty owner value. A missing owner property would be a different structure.

Text is not an in-memory object

A network response contains bytes that can be decoded into text. Parsing reads that text and creates values in your application’s memory. Serializing goes the other direction. Formatting only changes optional whitespace in the text.

A JavaScript object can contain functions or undefined, but these are not JSON values. Copying a JavaScript object literal directly into an API client can fail if it uses single quotes or unquoted property names.

A practical inspection workflow

  1. Check that the response status and content type match what you expected. An authentication error might return HTML.
  2. Use the validator if parsing fails. Fix the earliest syntax error first.
  3. Use the formatter to see nested values, or the viewer to open one branch.
  4. Check the API contract. Valid syntax does not tell you whether id must be a number or whether owner may be null.

Common assumptions to avoid

JSON has no native date, binary, or comment type. A timestamp is usually a string whose format is defined by an API. An array may contain mixed types unless the application imposes a stricter contract. A root value can be a scalar such as 42; an object is not required by the grammar.

Read the syntax guide for punctuation and escaping, or the schema guide for rules beyond syntax. The format is specified in RFC 8259.

If you have a .json file on your device, follow the file-opening guide to inspect it safely and understand what an extension does and does not tell you.

Already have valid JSON? Make it readable