-1

I've got a really small question about JSON objects. I've just read that:

JSON is built on two structures:

A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Now I have this example JSON object

{
     "firstName": "Peter",
     "lastName": "Meier",
     "age": 25,
     "childs":["Fritz","Julia"],
     "address":
     {
         "streetAddress": "21 Pilatusstrasse",
         "city": "Lucerne",
         "postalCode": "6000"
     },

 }

Its clear that the first 3 entries are name/value pairs and the 4th is a list. But what exactly is the 5th entry "address"? Is this seen as a name/value pair, where its value is a JSON object which itself again contains name/value pairs?

Thanks for the quick enlightning.

Herr Derb
  • 4,977
  • 5
  • 34
  • 62

1 Answers1

1

In the categorization scheme you cited, the 5th entry, "address", is a name-value pair. What makes the 5th different from the 1st to 3rd is that the value in the 5th is not a primitive type (number or string), but a JSON object itself. It can be called a nested object.

The 4th one is strictly speaking a name-value pair as well. It is just that its value is an ordered list.

To fall into the category of "ordered list", the JSON needs to start with "[", which is allowed in JSON.

See: can a JSON start with [?

Community
  • 1
  • 1
Shanqing Cai
  • 3,756
  • 3
  • 23
  • 36