jsonbeginnersapi

What is JSON? A Complete Beginner's Guide

·8 min read·JSON Concepts

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. Despite the "JavaScript" in the name, JSON is completely language-independent — every major programming language ships with a built-in JSON library. JSON is defined by RFC 8259 and originally popularized by Douglas Crockford at json.org.

When you call a REST API, configure a Node.js project with package.json, store documents in MongoDB, or read a GitHub webhook payload, you are working with JSON. It is the universal data format of the modern web.

The Six JSON Data Types

JSON supports exactly six value types — no more, no less:

TypeExampleNotes
String"Hello, World!"Must use double quotes — single quotes are invalid
Number42, 3.14, -7Integer or floating point, no NaN or Infinity
Booleantrue, falseLowercase only
NullnullRepresents the absence of a value
Object{ "key": "value" }Unordered key-value pairs; keys must be strings
Array[1, "two", true]Ordered list of any JSON values

A complete JSON document showing all six types:

json
{
  "name": "Ravi Mehta",
  "age": 28,
  "score": 98.5,
  "verified": true,
  "referral": null,
  "tags": ["developer", "designer"],
  "address": {
    "city": "Surat",
    "pincode": "395007"
  }
}

JSON Syntax Rules

JSON has strict syntax rules. Break any one of them and every parser throws an error:

RuleValidInvalid
Keys must be strings"name": "Ravi"name: "Ravi"
Strings use double quotes"city": "Surat"'city': 'Surat'
No trailing comma{"a": 1, "b": 2}{"a": 1, "b": 2,}
No comments// this is a comment
No undefined or NaN"val": null"val": undefined
Booleans are lowercasetrue, falseTrue, False

JSON vs XML — A Quick Comparison

Before JSON became dominant, XML was the standard. Here is the same data in both formats:

xml
<!-- XML — verbose, requires closing tags -->
<user>
  <name>Ravi Mehta</name>
  <age>28</age>
  <verified>true</verified>
</user>
json
{ "name": "Ravi Mehta", "age": 28, "verified": true }

JSON wins on brevity, native browser support, and direct mapping to programming language objects and arrays. XML is still used for SOAP APIs, RSS feeds, and document formats like Microsoft Office.

Parsing and Generating JSON in JavaScript

Every modern browser and Node.js runtime includes two global functions for working with JSON:

javascript
// JSON.parse — convert a JSON string into a JavaScript value
const jsonString = '{"name":"Ravi","age":28}';
const obj = JSON.parse(jsonString);
console.log(obj.name); // => "Ravi"

// JSON.stringify — convert a JavaScript value into a JSON string
const data = { name: "Ravi", age: 28, score: 98.5 };
const str = JSON.stringify(data);          // minified
const pretty = JSON.stringify(data, null, 2); // formatted with 2-space indent

// Always use try/catch — JSON.parse throws on invalid input
try {
  const parsed = JSON.parse(rawInput);
} catch (e) {
  console.error("Invalid JSON:", e.message);
}

Key behaviors of JSON.stringify you should know: - undefined values in objects are silently dropped (the key disappears) - undefined values in arrays become null - Functions, Symbols, and circular references cannot be serialized - NaN and Infinity both become null

JSON in Other Languages

python
# Python
import json
obj = json.loads('{"name": "Ravi", "age": 28}')
print(obj["name"])  # => Ravi
back = json.dumps(obj, indent=2)
go
// Go
import "encoding/json"
type User struct {
  Name string `json:"name"`
  Age  int    `json:"age"`
}
var u User
json.Unmarshal([]byte(`{"name":"Ravi","age":28}`), &u)

Common Use Cases

  • REST APIs — virtually every API today sends and receives JSON
  • Configuration files — package.json, tsconfig.json, .eslintrc.json
  • Database documents — MongoDB, Firestore, DynamoDB, and PostgreSQL JSONB columns all store JSON
  • Browser storage — localStorage and sessionStorage via JSON.stringify/parse
  • Message queues — Kafka, SQS, and RabbitMQ payloads are typically JSON
  • Log aggregation — structured JSON logs are indexable and queryable in tools like Datadog and CloudWatch

Common Mistakes Beginners Make

  1. Trailing comma after the last property or array element — {"a":1,} is invalid
  2. Single quotes{'name':'Ravi'} is not JSON; use {"name":"Ravi"}
  3. Unquoted keys{name:"Ravi"} is JavaScript object literal syntax, not JSON
  4. Comments — JSON has no comment syntax; remove them before parsing
  5. undefined — not a JSON type; replace with null or omit the field

Use JSONKit's JSON Formatter to instantly catch all of these errors with line-and-column error messages.

Tools to Work with JSON

JSONKit provides a full set of free browser-based tools:

All tools run entirely in your browser. Your data is never sent to any server.

References

Try JSON Formatter

Paste your JSON and format it instantly in your browser.