0

I'm quite new to Json data structure and so unable to extract data from it.

This is the sample rows from Json data which is stored in csv file

row1)   {"results":[{"address_components":[{"long_name":"16","short_name":"16","types":["street_number"]},{"long_name":"Bhagwan Tatyasaheb Kawade Road","short_name":"BT Kawde Road","types":["route"]},{"long_name":"Palmgrove Society","short_name":"Palmgrove Society","types":["neighborhood","political"]},{"long_name":"Uday Baug","short_name":"Uday Baug","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Ghorpadi","short_name":"Ghorpadi","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]},{"long_name":"411001","short_name":"411001","types":["postal_code"]}],"formatted_address":"16, BT Kawade Road, Palmgrove Society, Uday Baug, Ghorpadi, Pune, Maharashtra 411001, India","geometry":{"location":{"lat":18.5132611,"lng":73.907346},"location_type":"ROOFTOP","viewport":{"northeast":{"lat":18.5146100802915,"lng":73.90869498029151},"southwest":{"lat":18.51191211970849,"lng":73.90599701970851}}},"place_id":"ChIJo1QsU7nBwjsRiewRdiNc2i4","types":["street_address"]},{"address_components":[{"long_name":"Jambhulkar Mala","short_name":"Jambhulkar Mala","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Jambhulkar Mala, Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}},"location":{"lat":18.508659,"lng":73.9029138},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}}},"place_id":"ChIJJ0lCDMfBwjsRrPmUq2ZOxd8","types":["political","sublocality","sublocality_level_2"]},{"address_components":[{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}},"location":{"lat":18.4828904,"lng":73.9016832},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}}},"place_id":"ChIJ8TQ7l8LBwjsROUGpMh25HMw","types":["political","sublocality","sublocality_level_1"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Prabhag 36","short_name":"Prabhag 36","types":["administrative_area_level_3","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}},"location":{"lat":18.5204303,"lng":73.8567437},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}}},"place_id":"ChIJARFGZy6_wjsRQ-Oenb9DjYI","types":["locality","political"]},{"address_components":[{"long_name":"411040","short_name":"411040","types":["postal_code"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra 411040, India","geometry":{"bounds":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}},"location":{"lat":18.492095,"lng":73.90017759999999},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}}},"place_id":"ChIJ-64DzdvBwjsRKzv08MBrn18","types":["postal_code"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":19.38404,"lng":75.16309},"southwest":{"lat":17.89324,"lng":73.32352}},"location":{"lat":18.6832564,"lng":74.0300122},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":19.38404,"lng":75.1447465},"southwest":{"lat":17.89324,"lng":73.32352}}},"place_id":"ChIJQ97RPE_AwjsR5zbDDbo3wHI","types":["administrative_area_level_2","political"]},{"address_components":[{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":22.028441,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}},"location":{"lat":19.7514798,"lng":75.7138884},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":22.0279091,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}}},"place_id":"ChIJ-dacnB7EzzsRtk_gS5IiLxs","types":["administrative_area_level_1","political"]},{"address_components":[{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"India","geometry":{"bounds":{"northeast":{"lat":35.5087008,"lng":97.39535869999999},"southwest":{"lat":6.4626999,"lng":68.1097}},"location":{"lat":20.593684,"lng":78.96288},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":35.5087008,"lng":97.39498069999999},"southwest":{"lat":6.7535159,"lng":68.16288519999999}}},"place_id":"ChIJkbeSa_BfYzARphNChaFPjNc","types":["country","political"]},{"address_components":[{"long_name":"Uday Baug","short_name":"Uday Baug","types":["bus_station","establishment","point_of_interest","transit_station"]},{"long_name":"Uday Baug","short_name":"Uday Baug","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Ghorpadi","short_name":"Ghorpadi","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]},{"long_name":"411001","short_name":"411001","types":["postal_code"]}],"formatted_address":"Uday Baug, Ghorpadi, Pune, Maharashtra 411001, India","geometry":{"location":{"lat":18.510892,"lng":73.906956},"location_type":"GEOMETRIC_CENTER","viewport":{"northeast":{"lat":18.5122409802915,"lng":73.9083049802915},"southwest":{"lat":18.5095430197085,"lng":73.90560701970848}}},"place_id":"ChIJ5YdfqcDBwjsR5VJutWLCsfA","types":["bus_station","establishment","point_of_interest","transit_station"]}],"status":"OK"}
row2) {"results":[{"address_components":[{"long_name":"Canal Road","short_name":"Canal Rd","types":["route"]},{"long_name":"Empress Garden View Society","short_name":"Empress Garden View Society","types":["political","sublocality","sublocality_level_3"]},{"long_name":"Uday Baug","short_name":"Uday Baug","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Ghorpadi","short_name":"Ghorpadi","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]},{"long_name":"411001","short_name":"411001","types":["postal_code"]}],"formatted_address":"Canal Rd, Empress Garden View Society, Uday Baug, Ghorpadi, Pune, Maharashtra 411001, India","geometry":{"bounds":{"northeast":{"lat":18.510637,"lng":73.9070137},"southwest":{"lat":18.5102785,"lng":73.9016839}},"location":{"lat":18.510445,"lng":73.90438309999999},"location_type":"GEOMETRIC_CENTER","viewport":{"northeast":{"lat":18.5118067302915,"lng":73.9070137},"southwest":{"lat":18.50910876970849,"lng":73.9016839}}},"place_id":"ChIJ88lKe8fBwjsRCRKukkS6-nM","types":["route"]},{"address_components":[{"long_name":"Jambhulkar Mala","short_name":"Jambhulkar Mala","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Jambhulkar Mala, Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}},"location":{"lat":18.508659,"lng":73.9029138},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}}},"place_id":"ChIJJ0lCDMfBwjsRrPmUq2ZOxd8","types":["political","sublocality","sublocality_level_2"]},{"address_components":[{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}},"location":{"lat":18.4828904,"lng":73.9016832},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}}},"place_id":"ChIJ8TQ7l8LBwjsROUGpMh25HMw","types":["political","sublocality","sublocality_level_1"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Prabhag 36","short_name":"Prabhag 36","types":["administrative_area_level_3","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}},"location":{"lat":18.5204303,"lng":73.8567437},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}}},"place_id":"ChIJARFGZy6_wjsRQ-Oenb9DjYI","types":["locality","political"]},{"address_components":[{"long_name":"411040","short_name":"411040","types":["postal_code"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra 411040, India","geometry":{"bounds":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}},"location":{"lat":18.492095,"lng":73.90017759999999},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}}},"place_id":"ChIJ-64DzdvBwjsRKzv08MBrn18","types":["postal_code"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":19.38404,"lng":75.16309},"southwest":{"lat":17.89324,"lng":73.32352}},"location":{"lat":18.6832564,"lng":74.0300122},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":19.38404,"lng":75.1447465},"southwest":{"lat":17.89324,"lng":73.32352}}},"place_id":"ChIJQ97RPE_AwjsR5zbDDbo3wHI","types":["administrative_area_level_2","political"]},{"address_components":[{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":22.028441,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}},"location":{"lat":19.7514798,"lng":75.7138884},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":22.0279091,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}}},"place_id":"ChIJ-dacnB7EzzsRtk_gS5IiLxs","types":["administrative_area_level_1","political"]},{"address_components":[{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"India","geometry":{"bounds":{"northeast":{"lat":35.5087008,"lng":97.39535869999999},"southwest":{"lat":6.4626999,"lng":68.1097}},"location":{"lat":20.593684,"lng":78.96288},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":35.5087008,"lng":97.39498069999999},"southwest":{"lat":6.7535159,"lng":68.16288519999999}}},"place_id":"ChIJkbeSa_BfYzARphNChaFPjNc","types":["country","political"]}],"status":"OK"}
row3) {"results":[{"address_components":[{"long_name":"Canal Road","short_name":"Canal Rd","types":["route"]},{"long_name":"Empress Garden View Society","short_name":"Empress Garden View Society","types":["political","sublocality","sublocality_level_3"]},{"long_name":"Uday Baug","short_name":"Uday Baug","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Ghorpadi","short_name":"Ghorpadi","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]},{"long_name":"411001","short_name":"411001","types":["postal_code"]}],"formatted_address":"Canal Rd, Empress Garden View Society, Uday Baug, Ghorpadi, Pune, Maharashtra 411001, India","geometry":{"bounds":{"northeast":{"lat":18.510637,"lng":73.9070137},"southwest":{"lat":18.5102785,"lng":73.9016839}},"location":{"lat":18.510445,"lng":73.90438309999999},"location_type":"GEOMETRIC_CENTER","viewport":{"northeast":{"lat":18.5118067302915,"lng":73.9070137},"southwest":{"lat":18.50910876970849,"lng":73.9016839}}},"place_id":"ChIJ88lKe8fBwjsRCRKukkS6-nM","types":["route"]},{"address_components":[{"long_name":"Jambhulkar Mala","short_name":"Jambhulkar Mala","types":["political","sublocality","sublocality_level_2"]},{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Jambhulkar Mala, Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}},"location":{"lat":18.508659,"lng":73.9029138},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.510584,"lng":73.9071699},"southwest":{"lat":18.5064841,"lng":73.89949709999999}}},"place_id":"ChIJJ0lCDMfBwjsRrPmUq2ZOxd8","types":["political","sublocality","sublocality_level_2"]},{"address_components":[{"long_name":"Wanowrie","short_name":"Wanowrie","types":["political","sublocality","sublocality_level_1"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Wanowrie, Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}},"location":{"lat":18.4828904,"lng":73.9016832},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.512962,"lng":73.9174169},"southwest":{"lat":18.480897,"lng":73.8890401}}},"place_id":"ChIJ8TQ7l8LBwjsROUGpMh25HMw","types":["political","sublocality","sublocality_level_1"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Prabhag 36","short_name":"Prabhag 36","types":["administrative_area_level_3","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}},"location":{"lat":18.5204303,"lng":73.8567437},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.6357545,"lng":73.9864569},"southwest":{"lat":18.4134784,"lng":73.7394779}}},"place_id":"ChIJARFGZy6_wjsRQ-Oenb9DjYI","types":["locality","political"]},{"address_components":[{"long_name":"411040","short_name":"411040","types":["postal_code"]},{"long_name":"Pune","short_name":"Pune","types":["locality","political"]},{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra 411040, India","geometry":{"bounds":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}},"location":{"lat":18.492095,"lng":73.90017759999999},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":18.5105018,"lng":73.9287002},"southwest":{"lat":18.4785059,"lng":73.87890030000001}}},"place_id":"ChIJ-64DzdvBwjsRKzv08MBrn18","types":["postal_code"]},{"address_components":[{"long_name":"Pune","short_name":"Pune","types":["administrative_area_level_2","political"]},{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Pune, Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":19.38404,"lng":75.16309},"southwest":{"lat":17.89324,"lng":73.32352}},"location":{"lat":18.6832564,"lng":74.0300122},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":19.38404,"lng":75.1447465},"southwest":{"lat":17.89324,"lng":73.32352}}},"place_id":"ChIJQ97RPE_AwjsR5zbDDbo3wHI","types":["administrative_area_level_2","political"]},{"address_components":[{"long_name":"Maharashtra","short_name":"MH","types":["administrative_area_level_1","political"]},{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"Maharashtra, India","geometry":{"bounds":{"northeast":{"lat":22.028441,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}},"location":{"lat":19.7514798,"lng":75.7138884},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":22.0279091,"lng":80.890924},"southwest":{"lat":15.6024121,"lng":72.659363}}},"place_id":"ChIJ-dacnB7EzzsRtk_gS5IiLxs","types":["administrative_area_level_1","political"]},{"address_components":[{"long_name":"India","short_name":"IN","types":["country","political"]}],"formatted_address":"India","geometry":{"bounds":{"northeast":{"lat":35.5087008,"lng":97.39535869999999},"southwest":{"lat":6.4626999,"lng":68.1097}},"location":{"lat":20.593684,"lng":78.96288},"location_type":"APPROXIMATE","viewport":{"northeast":{"lat":35.5087008,"lng":97.39498069999999},"southwest":{"lat":6.7535159,"lng":68.16288519999999}}},"place_id":"ChIJkbeSa_BfYzARphNChaFPjNc","types":["country","political"]}],"status":"OK"}

I'm trying to extract the values from the first occurrence of address component

such that my dummy code looks like

I'm checking for these character vector

 chck_list=c("street_address","street_number","route","intersection","political","country","administrative_area_level_1","administrative_area_level_2","administrative_area_level_3","administrative_area_level_4","administrative_area_level_5","colloquial_area","locality","ward","sublocality","neighborhood","premise","subpremise","postal_code","natural_feature","airport","park","point_of_interest")

this is the trial code

 js <- fromJSON(as.character(json_data_df1[1:nrow(json_data_df1), 'Json_obj']))
    count_numb=list()
    Type=list()
    long_name=list()
    short_name=list()

    for(i in 1:nrows(js)){
    if(js$status=="ok"){
    count_numb[i] <- length(js[1:nrows(js)][grep("type",js$results[[1]]$address_components[[1]])]) #Counting number of times the word "type" occurs so that the loop can be iterated that many number of times.
    if(js$results[[1]]$address_components[[1]] %in% chck_list) {
    Type[i] = #print the word from the object chck_list that is present in data
    long_name[i] = #print the value of long_name from the data that corresponds to Type[i]
    short_name[i] = #print the value of short_name from the data that corresponds to Type[i]
    }
}

SO my o/p would look like

      Street_number  route                                neighborhood          sublocality_level_2     sublocality_level_1    Locality     Sub_locality_level_3             ....
1)      16            Bhagwan Tatyasaheb Kawade Road       Palmgrove Society     Uday Baug               Ghorpadi               Pune           NA                             ....
2)      NA            Canal Road                           NA                    Uday Baug               Ghorpadi               Pune         Empress Garden View Society                        
.       .                .
.       .                . 
.       .                .

P.S= json_data_df1 is the name of my data frame;; Json_obj is the name of the column in which Json object is present

Does anyone have any idea of how do I go for it.

Any help would be much appreciated.

Thanks.

Community
  • 1
  • 1
Andre_k
  • 1,680
  • 3
  • 18
  • 41

2 Answers2

1

I think you have first to use simplifyDataFrame = FALSE in the fromJSON function in order to get the data as a list:

dat = jsonlite::fromJSON("your_example_data.json", simplifyDataFrame = FALSE)

Then use a nested lapply to receive the three items of each sublist (I modified the lapply() function taking into account your last comment),

res = lapply(dat, function(x) {

  lapply(x[["results"]], function(y) {

    do.call(rbind, lapply(y[['address_components']], function(z) {

      if (is.null(z)) {                            # if array is empty return NA's for all 3 output items

        c(rep(NA, 3))}

      else {

        tmp_array_type = z[['types']]               # temporarily get the json-array including "street_number", "route", "neighborhood" etc.

        if (length(tmp_array_type) == 0) {          # if array is of length 0 then return NA

          out_type = NA}

        else if (length(tmp_array_type) == 3) {     # it array is of length 3 return the 3rd item

          out_type = z[['types']][3]}

        else if (("political" %in% tmp_array_type) && length(tmp_array_type) > 1) {    # if array includes political and it's length is greater than 1 then remove political and then receive the 1st item

          tmp_array_type = tmp_array_type[-which(tmp_array_type == "political")]

          out_type = tmp_array_type[1]}

        else {

          out_type = tmp_array_type[1]                 # for all other cases return the 1st item of the array
        }

        c(out_type, z[['long_name']], z[['short_name']])
      }
    }))
  })
})

example output

[[1]]
[[1]][[1]]
      [,1]                          [,2]                             [,3]               
 [1,] "street_number"               "16"                             "16"               
 [2,] "route"                       "Bhagwan Tatyasaheb Kawade Road" "BT Kawde Road"    
 [3,] "neighborhood"                "Palmgrove Society"              "Palmgrove Society"
 [4,] "sublocality_level_2"         "Uday Baug"                      "Uday Baug"        
 [5,] "sublocality_level_1"         "Ghorpadi"                       "Ghorpadi"         
 [6,] "locality"                    "Pune"                           "Pune"             
 [7,] "administrative_area_level_2" "Pune"                           "Pune"             
 [8,] "administrative_area_level_1" "Maharashtra"                    "MH"               
 [9,] "country"                     "India"                          "IN"               
[10,] "postal_code"                 "411001"                         "411001"           

[[1]][[2]]
     [,1]                          [,2]              [,3]             
[1,] "sublocality_level_2"         "Jambhulkar Mala" "Jambhulkar Mala"
[2,] "sublocality_level_1"         "Wanowrie"        "Wanowrie"       
[3,] "locality"                    "Pune"            "Pune"           
[4,] "administrative_area_level_2" "Pune"            "Pune"           
[5,] "administrative_area_level_1" "Maharashtra"     "MH"             
[6,] "country"                

.....

If you want to modify the lapply() function or the ifelse statements then a good tutorial can be found here.

lampros
  • 581
  • 5
  • 12
  • Ohh this is nice but I think you missed out the "Type" column as expected in my output... – Andre_k Aug 10 '17 at 10:34
  • I edited the answer to account for the "types" column. – lampros Aug 10 '17 at 10:40
  • I have the JSON content stored in a csv file. which I imported in R and name that object as "json_data_df". so after running the first line of code i.e "dat = jsonlite::fromJSON("json_data_df", simplifyDataFrame = FALSE)" gave me error "Error: Argument 'txt' must be a JSON string, URL or file.". so I changed it to character "dat = jsonlite::fromJSON(as.character(json_data_df), simplifyDataFrame = FALSE)". but still it gave error "Error: lexical error: invalid char in json text. c("{\"results\":[{\"address_com (right here) ------^" – Andre_k Aug 10 '17 at 10:47
  • The jsonlite::fromJSON() function expects the input to be either a string, a url or a file. I would suggest to use the path to the .csv file as input to the function, such as jsonlite::fromJSON("your_example_file.csv"). However, I thought that your input file is of .json type. – lampros Aug 10 '17 at 10:55
  • Still giving me the error after using this statement "dat = jsonlite::fromJSON("C:/Users/JSON Sample.csv", simplifyDataFrame = FALSE)" "Error in parse_con(txt, bigint_as_char) : parse error: trailing garbage "{""results"":[{""address_components"":[{" (right here) ------^" .... this csv file contains a single column with list of such JSON objects per row and it doesn't have a column name, will that affect? – Andre_k Aug 10 '17 at 11:04
  • have you checked inserting those three sample rows into a csv and then executing the code??? – Andre_k Aug 10 '17 at 11:15
  • Although I would suggest to download the data as a .json file the solution to the error would be to import the .csv as you have done initially and then save the data.frame as a .json file using **jsonlite::write_json(json_data_df, "your_example_data.json")**. Then continue as I suggested. – lampros Aug 10 '17 at 11:16
  • Changing the file extension also didn't helped, I change JSON Sample.csv to JSON Sample.json. and still encountered with same error. – Andre_k Aug 10 '17 at 11:20
  • I followed your method i.e write_json(json_data_df, "your_example_data.json") and when I ran the code , it gave me empty records in output " head(res) [[1]] list() [[2]] list() [[3]] list() [[4]] list() [[5]] list() [[6]] list()" – Andre_k Aug 10 '17 at 11:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/151593/discussion-between-deepesh-and-lampros). – Andre_k Aug 10 '17 at 11:27
  • A small change is been expected i.e the code is taking first element but in one case it should take second element . Detailed have been posted in the following link " https://stackoverflow.com/questions/45627646/accessing-only-second-sub-element-from-json-object-in-r " – Andre_k Aug 11 '17 at 05:36
  • @Iampros updated the post with character vector for which I want to check for the existence of it. – Andre_k Aug 11 '17 at 13:16
  • @deepesh, the *chck_list* includes the majority of the types appearing in each row. I thought there are specific types. How should I pick one specific type of the array ["political","sublocality","sublocality_level_1"] if two of those appear in the *chck_list* ("political","sublocality")? – lampros Aug 11 '17 at 13:47
  • Always excluding the word "political" whenever it appears in the list ("political" , "xxx", "xxx") and if there are three elements in an array then taking 3rd element from that array ("political","sub-locality","sub-locality1")/ ("political","sub-locality","sub-locality2") so accessing "sub-locality1" and "sub-locality2" from the array. If that could be possible? – Andre_k Aug 12 '17 at 12:43
  • I think there could be one last edit in your code, because I had to again re post the question with another update. i.e a transpose of those rows. – Andre_k Aug 14 '17 at 08:45
1

There are a few geocoding packages available that will make your life easier for you, such as my googleway package that queries various Google APIs and 'simplifies' the results into data.frames / lists. From there you can extract your required elements using standard list/data.frame subsetting methods.

library(googleway)

addresses <- c("Bhagwan Tatyasaheb Kawade Road", "Empress Garden View Society")
apiKey <- 'your_api_key'

lst_geocode <- lapply(addresses, function(x){
    google_geocode(address = x,
                                 key = apiKey)
})

lapply(lst_geocode, function(x){
    x[['results']][['address_components']]
})

# [[1]]
# [[1]][[1]]
# long_name    short_name                                  types
# 1 Bhagwan Tatyasaheb Kawade Road BT Kawde Road                                  route
# 2                           Pune          Pune                    locality, political
# 3                           Pune          Pune administrative_area_level_2, political
# 4                    Maharashtra            MH administrative_area_level_1, political
# 5                          India            IN                     country, political
# 
# 
# [[2]]
# [[2]][[1]]
# long_name         short_name                                       types
# 1    Sopan Baug Road      Sopan Baug Rd                                       route
# 2 Sopan Baug Society Sopan Baug Society political, sublocality, sublocality_level_3
# 3        Kavade Mala        Kavade Mala political, sublocality, sublocality_level_2
# 4           Ghorpadi           Ghorpadi political, sublocality, sublocality_level_1
# 5               Pune               Pune                         locality, political
# 6               Pune               Pune      administrative_area_level_2, political
# 7        Maharashtra                 MH      administrative_area_level_1, political
# 8              India                 IN                          country, political
# 9             411001             411001                                 postal_code
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
  • What does "apiKey" means here?? And does addresses are my json data? – Andre_k Aug 16 '17 at 05:09
  • @deepesh - to use any Google API you need [an API key](https://developers.google.com/maps/documentation/javascript/get-api-key). There are ways to avoid using it, as per the `geocode` function in the `ggmap` library, but Google specifies you need to have one to use their service. – SymbolixAU Aug 16 '17 at 05:20
  • @deepesh - and I'm sorry, I don't understand the second part of your comment – SymbolixAU Aug 16 '17 at 05:21
  • @SymbolixAU- the JSON data which I'm getting as an input is either in .csv format or in .json format..So i don't think I should think about api_key. I just reading the csv file or .json file in R and trying to extract the data from it in a given manner. My second question was that the what eaxctly the object "addresses" hold ,is it the json data or something else? – Andre_k Aug 16 '17 at 05:26
  • Another thing is that the format in which I'm expecting the output is in the transpose way of your output .Alternatively you can go through this post as well " https://stackoverflow.com/questions/45671463/extracting-address-component-of-json-object-column-wise-in-r" – Andre_k Aug 16 '17 at 05:29
  • @deepesh - Ok I see. My answer was to highlight that as your data appears to be derived from Google's Geocoding API, that there are other ways to get the data from its source. So it's not a direct answer to your question, but merely highlights an alternative way to get the data in the first place. – SymbolixAU Aug 16 '17 at 05:33
  • 1
    Yes yours is a nice way to extract the data, +1 for "googleway". But any suggestion on how to go about my problem such that I get the required output format. – Andre_k Aug 16 '17 at 05:36