how normalize JSON GET response when the type is <class str>?

Viewed 48

I want to convert the JSON response into a pandas dataframe( All Names, All IDs,All created which you can see in JSON. into a dataframe ) . Because the data is bigdata I Do NOT want to use loops.

This is my code:

req = urllib.request.Request(url, headers=hdr)
    req.get_method = lambda: 'GET'
    response = urllib.request.urlopen(req)
    ### Response: 200 OK
    print(response.getcode())
    ### JSON Output
    print(response.read())

and this is the JSON GET response:

200
b'{
    "results": [{
            "accountId": "d85b3704-XXXXXX-aecc-2886629c732e",
            "id": "69fb205b25",
            "partition": null,
            "externalId": null,
            "metadata": null,
            "name": "New",
            "description": null,
            "created": "2022-09-19T17:55:58.244+00:00",
            "lastModified": "2022-09-19T17:56:05.107+00:00",
            "lastIndexed": "2022-09-19T17:56:05.107+00:00",
            "privacyMode": "Private",
            38be7bf5ba99",
            "searchMatches": [],
            "indexingPreset": "Default",
            "streamingPreset": "Default",
            "sourceLanguage": "en-US",
            "sourceLanguages": ["en-US"],
            "personModelId": "00000000-0000-0000-0000-000000000000"
        }

How can do it without loops?

(I am using Google Colab)

1 Answers

You can use:

pandas.json_normalize(
    json_list, 
    record_path =['results'], 
    meta=['id', 'name'] )
Related