JSON Data

JSON (JavaScript Object Notation) is a lightweight, easy-to-read format used to store and exchange data. It’s widely used in web development, APIs, and configuration files. To understand how JSON works, it’s essential to learn about its data types.

In JSON, data is represented as name/value pairs. Each value can be one of the following data types:


1. String

A string is a sequence of characters, enclosed in double quotes.

Example:

jsonCopyEdit"name": "Alice"
  • Strings can contain letters, numbers, spaces, and special characters.
  • Single quotes (') are not allowed — only double quotes.

2. Number

Numbers in JSON can be integers or floating-point (decimals). Unlike JavaScript, JSON only supports decimal notation (no NaN, Infinity, or hex values).

Example:

jsonCopyEdit"age": 30,
"height": 5.7
  • No quotes are used for numbers.
  • JSON does not allow leading zeros (012 is invalid).

3. Boolean

The boolean data type represents logical values: true or false.

Example:

jsonCopyEdit"isMember": true,
"isAdmin": false
  • Do not use quotes; true and false must be lowercase.

4. Array

An array is an ordered list of values, enclosed in square brackets [ ]. The values can be of any type: strings, numbers, booleans, objects, or even other arrays.

Example:

jsonCopyEdit"colors": ["red", "green", "blue"],
"scores": [100, 98, 95]
  • Arrays maintain the order of elements.
  • Each item is separated by a comma.

5. Object

An object is a collection of key-value pairs, enclosed in curly braces { }. Keys must be strings and should be unique within the same object.

Example:

jsonCopyEdit"address": {
  "street": "123 Main St",
  "city": "New York",
  "zip": "10001"
}
  • Objects can contain other objects or arrays (nested structures).
  • Keys are always in double quotes.

6. Null

The null type represents a null or empty value. It is used when a value is unknown or intentionally empty.

Example:

jsonCopyEdit"middleName": null
  • Must be written in lowercase, without quotes.

Summary of JSON Data Types

TypeDescriptionExample
StringText enclosed in double quotes"name": "John"
NumberNumeric value"age": 25
Booleantrue or false"isActive": false
ArrayOrdered list of values"items": [1, 2, 3]
ObjectCollection of key/value pairs"user": {"name": "Jane"}
NullRepresents no value"deleted": null

Final Notes

  • JSON is language-independent, meaning it can be used across many programming languages like Python, JavaScript, Java, and more.
  • Always make sure your JSON is well-formed. Common mistakes include missing commas, improper quotes, or using unsupported values.

Example of Full JSON Object:

jsonCopyEdit{
  "name": "Alice",
  "age": 30,
  "isMember": true,
  "scores": [85, 90, 95],
  "contact": {
    "email": "alice@example.com",
    "phone": null
  }
}

This example includes all the core JSON data types in one structure.


Understanding these data types is the first step to using JSON effectively in real-world applications. Once you’re comfortable with them, you can move on to parsing, creating, and manipulating JSON data in your preferred programming language.

Leave a Reply

Your email address will not be published. Required fields are marked *