JSON Structure

JSON syntax is a superset of JavaScript object notation syntax:

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays

JSON Key-Values

JSON data is written as name/value pairs.

A name/value pair consists of a field name in double quotes, followed by a colon, followed by a value:

"address" : "10.1.1.1"

It is important to note that JSON names require double quotes and JavaScript names don't.

JSON

"name" : "GigabitEthernet0/0"
JavaScript

name : 'GigabitEthernet0/0'

JSON Data Types

As described above, a JSON very much resembles JavaScript object literal format. You can include the same basic data types inside JSON as you can in a standard JavaScript object :

  • string - a sequence of zero or more characters
  • number - a decimal number that may contain a fractional part
  • array -  an ordered list of values, each of which may be of any type wrapped in square brackets.
  • boolean - either of the values true or false

Let's have a look at how each data type is used in the following example: