0

I am trying to normalize a nested json response from this URL. As it is quite nested, i am not able to achieve the following format, can anyone help me in right direction?

Target Format

I am using this approach to normalize:

from urllib.request import urlopen
import json
from pandas.io.json import json_normalize
import  pandas as pd
class jsonResp():

   def __init__(self):
       global data
       global data1
       global path
       pd.set_option('display.max_rows', 500)
       pd.set_option('display.max_columns', 500)
       pd.set_option('display.width', 1000)
       requestURL = ("http://data.corkcity.ie/api/3/action/datastore_search?id=6cc1028e-7388-4bc5-95b7-667a59aa76dc") #Request urls for json
       responseOpen = urlopen(requestURL)
       elevations = responseOpen.read() #Reads the response
       data = json.loads(elevations) #Loads the json file for normalization and parsing
       df = pd.DataFrame.from_dict(json_normalize(data), orient='columns')
       print(df)


if __name__ == '__main__':
   obj = jsonResp()

Thanks

1 Answer 1

1

Start by navigating to the records and then use json_normalize():

import requests
json_data = requests.get("http://data.corkcity.ie/api/3/action/datastore_search?id=6cc1028e-7388-4bc5-95b7-667a59aa76dc").json()

from pandas.io.json import json_normalize

df = json_normalize(json_data["result"]["records"])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.