Please Like our Facebook Page

How to read sophisticated json data structure


Reading sophisticated json data is not fun, it’s actually headache and annoying. You might have found json data with too many json arrays and objects nested within each other in a way that they nothing less than a confusion. With that said, while json is hard for most of the users, it might be fun for most of us. Personally, I enjoy json and I like it especially when it’s highly nested and coiled. Under this tutorial am going to make you feel the fan.

What is Json Data

Json stands for Javascript Object Notation. Generally json is used for data interchange between different formats. Json structure is divided into two; json array and json object.

json array
Think of json array as the same arrays you have been using in general programming. All json array structure starts with square brackets and ends with square brackets ([] ). Following is an example of json array:

[
 
  {
    "id": "1",
    "title": "Title 1",
    "description": "Description 1"
  }, 
  {
    "id": "2",
    "title": "Title 2",
    "description": "Description 2"
  }
]

json Object
json objects are surrounded with curly braces ({}). Json objects are written in key/name pairs, keys are strings and values a valid json data types such as boolean, strings and integers. Please note json object can contain arrays, other objects and null. Following is an example of json object.

{  
   "results":[  
      {  
         "address_components":[  
            {  
               "long_name":"6",
               "short_name":"6",
               "types":[  
                  "street_number"
               ]
            },
            {  
               "long_name":"Bowery",
               "short_name":"Bowery",
               "types":[  
                  "route"
               ]
            },
            {  
               "long_name":"Lower Manhattan",
               "short_name":"Lower Manhattan",
               "types":[  
                  "neighborhood",
                  "political"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            },
            {  
               "long_name":"10013",
               "short_name":"10013",
               "types":[  
                  "postal_code"
               ]
            },
            {  
               "long_name":"5101",
               "short_name":"5101",
               "types":[  
                  "postal_code_suffix"
               ]
            }
         ],
         "formatted_address":"6 Bowery, New York, NY 10013, USA",
         "geometry":{  
            "location":{  
               "lat":40.7143182,
               "lng":-73.9976375
            },
            "location_type":"ROOFTOP",
            "viewport":{  
               "northeast":{  
                  "lat":40.7156671802915,
                  "lng":-73.9962885197085
               },
               "southwest":{  
                  "lat":40.7129692197085,
                  "lng":-73.9989864802915
               }
            }
         },
         "place_id":"ChIJa3-9WCZawokRRj8gZry7Pd0",
         "types":[  
            "street_address"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"Am USA Express Inc",
               "short_name":"Am USA Express Inc",
               "types":[  
                  "establishment",
                  "point_of_interest"
               ]
            },
            {  
               "long_name":"4c",
               "short_name":"4c",
               "types":[  
                  "subpremise"
               ]
            },
            {  
               "long_name":"16",
               "short_name":"16",
               "types":[  
                  "street_number"
               ]
            },
            {  
               "long_name":"Bowery",
               "short_name":"Bowery",
               "types":[  
                  "route"
               ]
            },
            {  
               "long_name":"Chinatown",
               "short_name":"Chinatown",
               "types":[  
                  "neighborhood",
                  "political"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            },
            {  
               "long_name":"10013",
               "short_name":"10013",
               "types":[  
                  "postal_code"
               ]
            }
         ],
         "formatted_address":"Am USA Express Inc, 16 Bowery #4c, New York, NY 10013, USA",
         "geometry":{  
            "location":{  
               "lat":40.7145761,
               "lng":-73.9975439
            },
            "location_type":"ROOFTOP",
            "viewport":{  
               "northeast":{  
                  "lat":40.71592508029149,
                  "lng":-73.9961949197085
               },
               "southwest":{  
                  "lat":40.71322711970849,
                  "lng":-73.9988928802915
               }
            }
         },
         "place_id":"ChIJ-aWpYllZwokRU8_qtbnMVR0",
         "types":[  
            "establishment",
            "point_of_interest"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"Chinatown",
               "short_name":"Chinatown",
               "types":[  
                  "neighborhood",
                  "political"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"Chinatown, New York, NY, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.71936549999999,
                  "lng":-73.9897026
               },
               "southwest":{  
                  "lat":40.7127979,
                  "lng":-74.0040592
               }
            },
            "location":{  
               "lat":40.7157509,
               "lng":-73.9970307
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.71936549999999,
                  "lng":-73.9897026
               },
               "southwest":{  
                  "lat":40.7127979,
                  "lng":-74.0040592
               }
            }
         },
         "place_id":"ChIJDcEvbPVZwokRETEfzXATns8",
         "types":[  
            "neighborhood",
            "political"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"Lower Manhattan",
               "short_name":"Lower Manhattan",
               "types":[  
                  "neighborhood",
                  "political"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"Lower Manhattan, New York, NY, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.7425263,
                  "lng":-73.97164459999999
               },
               "southwest":{  
                  "lat":40.7004631,
                  "lng":-74.01933500000001
               }
            },
            "location":{  
               "lat":40.7230084,
               "lng":-74.00063279999999
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.7425263,
                  "lng":-73.97164459999999
               },
               "southwest":{  
                  "lat":40.7004631,
                  "lng":-74.01933500000001
               }
            }
         },
         "place_id":"ChIJi4MZVIhZwokRPNvWbi-c0wI",
         "types":[  
            "neighborhood",
            "political"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"Manhattan, New York, NY, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.882214,
                  "lng":-73.907
               },
               "southwest":{  
                  "lat":40.6803955,
                  "lng":-74.047285
               }
            },
            "location":{  
               "lat":40.7830603,
               "lng":-73.9712488
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.820045,
                  "lng":-73.90331300000001
               },
               "southwest":{  
                  "lat":40.698078,
                  "lng":-74.03514899999999
               }
            }
         },
         "place_id":"ChIJYeZuBI9YwokRjMDs_IEyCwo",
         "types":[  
            "political",
            "sublocality",
            "sublocality_level_1"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"New York, NY, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.9175771,
                  "lng":-73.70027209999999
               },
               "southwest":{  
                  "lat":40.4773991,
                  "lng":-74.25908989999999
               }
            },
            "location":{  
               "lat":40.7127837,
               "lng":-74.0059413
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.9175771,
                  "lng":-73.70027209999999
               },
               "southwest":{  
                  "lat":40.4773991,
                  "lng":-74.25908989999999
               }
            }
         },
         "place_id":"ChIJOwg_06VPwokRYv534QaPC8g",
         "types":[  
            "locality",
            "political"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"10013",
               "short_name":"10013",
               "types":[  
                  "postal_code"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"New York, NY 10013, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.728263,
                  "lng":-73.994378
               },
               "southwest":{  
                  "lat":40.7118841,
                  "lng":-74.0215158
               }
            },
            "location":{  
               "lat":40.7217861,
               "lng":-74.0094471
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.728263,
                  "lng":-73.994378
               },
               "southwest":{  
                  "lat":40.7118841,
                  "lng":-74.0215158
               }
            }
         },
         "place_id":"ChIJJ0lE74pZwokRhNa5sMUkozk",
         "types":[  
            "postal_code"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"New York County",
               "short_name":"New York County",
               "types":[  
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {  
               "long_name":"Manhattan",
               "short_name":"Manhattan",
               "types":[  
                  "political",
                  "sublocality",
                  "sublocality_level_1"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"New York",
               "types":[  
                  "locality",
                  "political"
               ]
            },
            {  
               "long_name":"New York",
               "short_name":"NY",
               "types":[  
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"New York County, New York, NY, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":40.882214,
                  "lng":-73.907
               },
               "southwest":{  
                  "lat":40.6803955,
                  "lng":-74.047285
               }
            },
            "location":{  
               "lat":40.7830603,
               "lng":-73.9712488
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":40.882214,
                  "lng":-73.907
               },
               "southwest":{  
                  "lat":40.6803955,
                  "lng":-74.047285
               }
            }
         },
         "place_id":"ChIJOwE7_GTtwokRFq0uOwLSE9g",
         "types":[  
            "administrative_area_level_2",
            "political"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"New York-Northern New Jersey-Long Island, NY-NJ-PA",
               "short_name":"New York-Northern New Jersey-Long Island, NY-NJ-PA",
               "types":[  
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"New York-Northern New Jersey-Long Island, NY-NJ-PA, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":41.6018065,
                  "lng":-71.856214
               },
               "southwest":{  
                  "lat":39.49853299999999,
                  "lng":-75.3585939
               }
            },
            "location":{  
               "lat":40.9590293,
               "lng":-74.0300122
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":41.6018065,
                  "lng":-71.856214
               },
               "southwest":{  
                  "lat":39.49853299999999,
                  "lng":-75.3585939
               }
            }
         },
         "place_id":"ChIJ3YJV4PRWwokRFFI21ZrHXtQ",
         "types":[  
            "political"
         ]
      },
      {  
         "address_components":[  
            {  
               "long_name":"New York Metropolitan Area",
               "short_name":"New York Metropolitan Area",
               "types":[  
                  "political"
               ]
            },
            {  
               "long_name":"United States",
               "short_name":"US",
               "types":[  
                  "country",
                  "political"
               ]
            }
         ],
         "formatted_address":"New York Metropolitan Area, USA",
         "geometry":{  
            "bounds":{  
               "northeast":{  
                  "lat":42.0809059,
                  "lng":-71.777491
               },
               "southwest":{  
                  "lat":39.475198,
                  "lng":-75.3587649
               }
            },
            "location":{  
               "lat":40.7127761,
               "lng":-74.0059544
            },
            "location_type":"APPROXIMATE",
            "viewport":{  
               "northeast":{  
                  "lat":42.0809059,
                  "lng":-71.777491
               },
               "southwest":{  
                  "lat":39.475198,
                  "lng":-75.3587649
               }
            }
         },
         "place_id":"ChIJ-5Z24NaGwokRiMh4Rj8FNMo",
         "types":[  
            "political"
         ]
      }
   ],
   "status":"OK"
}

Now let’s try to read above json data, our json feed is a json object. All json feed enclosed by curly braces are called json objects. Above json object contains json arrays and json objects nested inside. Now let’s try to read it.
Our json object contains two children only, i.e json array (results) and json object (status). Lets focus our eyes on results – json array. Results array contains several objects and each object contains json array, for example, address_components is an array contained inside an object of results array. Json array address_components, has two keys with their values and one array, that is, long_name is a key containing value of 6 also, short_name is an object key containing value of 6, address_components array’s object also contains an array; types with value of street_number

That’s how simple it is to substructure json data

If you have any question regarding above feed, or I have made a mistake or many be there is something you did not understand, please let me know in the commenting system below. Also corrections are welcome. Comment and ask questions, I will help. Thank you










Please Like us on Facebook