JSON Format File

It is a format that allows us to create files in a very simple and at the same time well structured.
 
For our purposes you should only keep in mind the following:
  • All information in the file is recorded as properties of the form key: value
    • key - the pre-defined property whose name does not vary.
    • value - what we are assigning to the property.
  • All our properties are string and therefore their values must be between "", ie "key": "value"
  • The JSON file starts with { and ends with }
  • Objects - We can group more than one property by separating them by commas:
    • Objects also begin with { and end with }
    • Objects can contain two or more properties.
  • Arrays - We can group igual objects separating them by commas:
    • key will be the name of the array.
    • value is the array itself.
    • Arrays begin with [ and end with ]
    • Arrays may contain two or more objects.
 

Property

 
"key1": "value1"
 

Object

 
{
  "key2": "value2",
  "key3": "value3"
}
 

Array

 
"key4": [
  {
     "key5": "value5",
     "key6": "value6"
  },
  {
     "key5": "value7",
     "key6": "value8"
  },
  {
     "key5": "value9",
     "key6": "value10"
  }
]
 

JSON File Example (example.json)

 
Suppose we want to create our example.json file with the following structure:
  • A property (key1)
  • An array (key2) with two objects each with three properties (key3, key4, key5)
  • An array (key6) with three objects each with two properties (key7, key8)
 
{
  "key1": "value1",
  "key2": [
    {
       "key3": "value3",
       "key4": "value4",
       "key5": "value5"
    },
    {
       "key3": "value6",
       "key4": "value7",
       "key5": "value8"
    }
  ],
  "key6": [
    {
       "key7": "value10",
       "key8": "value11"
    },
    {
       "key7": "value12",
       "key8": "value13"
    },
    {
       "key7": "value14",
       "key8": "value15"
    }
  ]	
}