0

I have below json which I've got from some url:

{
    "abc":
      {
        "123":[45600,null,3567],
        "378":[78689,2345,5678],
        "343":[23456,null,null]
      }
}

it is stored in json_obj object:

json_obj = response.json()

I need to convert this json into dataframe, My code should be something like this :

df = pd.read_json(response,orient='columns')

so, that result should be :

          abc
123      [45600,null,3567]
378      [78689,2345,5678]
343      [23456,null,null]

But with above code I get error :

date_unit).parse()
  self._parse_no_numpy()
  loads(json, precise_float=self.precise_float), dtype=None)
  TypeError: Expected String or Unicode

If I replace response with url in the above code. it will work fine. But, I need to pass json_object instead of url.

Please give suggestions.

1 Answer 1

1
df = pd.read_json(response,orient='columns')

read_json() takes in JSON data. "response", i believe stores the API response for some request you're making.

response.json() would give you the python dictionary of the body of the response. You need to convert that to JSON. Try this:

import json
df = pd.read_json(json.dumps(response.json()),orient='columns')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.