Concepts / Introduction to JSON: A Simpler Data Format

Introduction to JSON: A Simpler Data Format

JSON uses two main structures: objects (key-value pairs in curly braces) and arrays (ordered lists in square brackets).

  • Programming

Why JSON Uses Two Structures

JSON stands for JavaScript Object Notation. It is a lightweight, text-based format for encoding and exchanging data across the web. Its central idea is simple: JSON organizes information with two main structures, objects and arrays. Objects describe named properties, while arrays represent ordered collections.

Objects and Key-Value Pairs

A JSON object is enclosed in curly braces. Inside it, information is arranged as key-value pairs. A key names a property, and its value supplies the associated data. Keys in JSON objects must be strings written in double quotes. Values may be strings, numbers, booleans, null, other objects, or arrays.

PersonobjectnamekeyagekeyAminavalue28valuecontainsmaps tocontainsmaps to
How does each key connect to its associated value inside a JSON object?
PartRole
KeyNames a property and must be a string in double quotes
ColonSeparates a key from its value
ValueStores the associated data
Curly bracesEnclose the object

The parts of a JSON object

Arrays and Ordered Collections

A JSON array is enclosed in square brackets. It represents an ordered list of values. The values in an array can be simple values, objects, or other arrays. Use an array when the data represents a collection of similar items rather than the named properties of one entity.

Objectcurly bracesname: Aminakey-value pairAminaordered valueArraysquare bracketsJonordered valuecontainsordersorders
What changes when data is enclosed in curly braces instead of square brackets?
StructureDelimitersBest suited forInternal organization
ObjectCurly bracesNamed properties of one entityKey-value pairs
ArraySquare bracketsA collection of similar itemsOrdered values

The two main JSON structures

Reading Nested Data

JSON structures can be nested. An object can contain another object or an array, and an array can contain objects. To read a nested structure, move from the outside inward: identify the top-level structure, find each key, and then inspect the value connected to that key. If that value is another object or array, repeat the same process.

Worked example

Tracing a contact record

Consider this generated JSON structure: an outer object has the keys name, phone, and email. The value of name is the string Amina. The value of phone is an object with the keys type and number. The value of email is an object with the key hide.

  1. 1
    Find the outer structure

    The record begins as an object, so its contents are organized as named key-value pairs.

  2. 2
    Read the simple value

    The key name connects to a string value, Amina.

  3. 3
    Enter the phone value

    The key phone connects to another object. That nested object groups the related properties type and number.

  4. 4
    Enter the email value

    The key email also connects to an object. That object contains the key hide.

  5. 5
    Describe the hierarchy

    The outer object represents one contact record, while the nested objects keep phone details and email details grouped under their related keys.

Result

The top-level object has three keys: name, phone, and email. The phone and email values are nested objects, so the structure contains related information at more than one level.

ContactobjectnameAminatypemobilehidefalsephoneobjectnumber555-0142emailobjectcontainscontainscontainscontainscontainscontains
What contains what when objects are nested inside a larger JSON object?

Objects Inside Arrays

Objects and arrays are not competing formats. They work together. An object can contain an array when one entity has a collection of related items. An array can contain objects when a collection contains several structured records. This combination lets JSON represent hierarchical data.

CatalogobjectproductsarrayProductobjectnameNotebookProductobjectnamePencontainsordersorderscontainscontains
How can JSON combine named properties with collections of structured items?

What do you think happens?

A collection contains several complete records, and each record has named properties. Which arrangement fits that description?

  • An object containing only simple values

  • An array containing objects

  • An object containing no key-value pairs

Reveal answer
Answer:

An array containing objects

The array represents the collection, while each object represents one structured record with named properties.

Syntax Mistakes to Avoid

  • Common mistake

    Treating curly braces and square brackets as interchangeable

    What it looks like

    Using an array when the data needs named properties, or using an object when the data is an ordered collection

    Why it fails

    The two structures communicate different organization: objects use key-value pairs, while arrays use ordered values.

    Do this instead

    Choose an object for the named properties of one entity and an array for a collection of similar items.

  • Common mistake

    Writing an object key without double quotes

    What it looks like

    name: Amina

    Why it fails

    JSON object keys must be strings in double quotes.

    Do this instead

    Represent the key as a double-quoted string.

  • Common mistake

    Stopping at the outermost object

    What it looks like

    Reading phone only as a single value even though it contains type and number

    Why it fails

    A value can itself be an object or an array, so nested content must also be inspected.

    Do this instead

    When a value is another object or array, move inward and read its contents.

  • Common mistake

    Assuming every JSON value is text

    What it looks like

    Treating a number, boolean, null value, object, or array as though it were a string

    Why it fails

    JSON values can have several forms, including strings, numbers, booleans, null, objects, and arrays.

    Do this instead

    Identify the value's type as you read the key-value pair.

Practice Reading Structure

EASY

A generated data record has an outer object with a key called students. The value of students is an array. The array contains two objects, and each object has the keys name and email. Explain what the outer object represents, what the array represents, and what each inner object represents.

Hints
  • Start with the outermost structure.
  • Identify whether the value of students is an object or an array.
  • Describe the role of each object inside the array.
Worked example

Practice solution

Interpret the generated record with an outer object, a students key, an array value, and two objects inside that array.

  1. 1
    Outer object

    The outer object groups the data under named properties.

  2. 2
    Students value

    The value connected to students is an array, so it represents a collection of student items.

  3. 3
    Array items

    Each item in the array is an object, so each item is one structured record.

  4. 4
    Inner properties

    The name and email keys provide named properties within each student record.

Result

The outer object describes a larger data structure, the students array holds a collection, and each object in that array describes one student using key-value pairs.

JSON in Data Exchange

JSON is widely encountered when data must move between systems. It has become a standard format for exchanging data across the web because it balances simplicity with expressiveness. It is easier to read and write than XML while remaining flexible enough to represent complex structures. Web APIs, databases, and other systems that send data from one place to another commonly use JSON.

Key point

The practical skill is not memorizing one sample record. It is recognizing the two structures and following their nesting. Once you can identify objects, arrays, keys, and values, you can begin interpreting much larger JSON data structures.

What to Remember

  1. 1
    JSON is a lightweight, text-based format for encoding and exchanging data.
  2. 2
    Objects use curly braces and organize information as key-value pairs.
  3. 3
    Arrays use square brackets and represent ordered lists of values.
  4. 4
    Object keys must be strings in double quotes, while values can be strings, numbers, booleans, null, objects, or arrays.
  5. 5
    Nesting lets objects and arrays work together to represent hierarchical data.

At a glance

  • JSON represents structured information with objects and arrays.
  • Objects use curly braces and key-value pairs for named properties.
  • Arrays use square brackets for ordered collections.
  • Nested objects and arrays allow related information to be grouped into hierarchical structures.
  • To read JSON, identify the current structure, follow each key to its value, and continue inward when the value is another object or array.

More concepts starting with I