Reputation: 217
I am translating some code from Python to Julia. I am trying to read a nested JSON into a DataFrame in Julia, is there any way to do it easily?
My Julia code:
r=HTTP.get(url_instrument_list,headers)
json_r=JSON.parse(String(r.body))
df_instruments=DataFrame(json_r["data"])
The json_r["data"]
object is a vector of dictionaries, but converting it directly to a DataFrame fails -- I am getting one column for "slots", one for "keys", one for "vals" rather than the actual column names in the data.
Equivalent Python code (that works):
r = requests.get(url_instrument_list, headers=headers)
df_instruments=pd.json_normalize(r.json()['data'])
Thanks!
Upvotes: 1
Views: 233
Reputation: 217
Update: I managed to solve the issue with the JSON3
package:
r=HTTP.get(url_instrument_list,headers)
json_r=JSON3.read(String(r.body))
df_instruments=DataFrame(json_r[:data])
Upvotes: 1