Skip to content

What is nesting?

Nesting involves putting arrays and objects inside each other, creating multiple layers of collections.

You can put arrays inside objects, objects inside arrays, arrays inside arrays, etc.

Sometimes a JSON file is one big object with lots of objects and arrays inside of that one top-level object.

An array of objects:

[
   "object",
   "object",
   "object"
]

An array of objects with values:

[
   {
      "name":"Ike",
      "age":33
   },
   {
      "name":"Cheryl",
      "age":21
   },
   {
      "name":"Joey",
      "age":55
   }
]

An object with an array in the value part of the key-value pair:

{
   "children":[
      "Mike",
      "Katie",
      "Tony",
      "Sally"
   ],
   "hobbies":[
      "running",
      "jumping",
      "hiking",
      "biking"
   ]
}

Sources