'How to get the nested part of a JSON string into a useable data table
I can get the top level of data using json_normalize. But when I try to set it for a nested part it returns an error. The json_normalize documentation isn't at all clear on what to put in the record_path and other variables. Under the main tree there is a field called liveData. Under that there is (for example) plays -- allPlays -- runners. I want the 3 fields under runners (movement, details, and credits) in a table, along with whatever key fields from the higher levels are relevant, so it is a relational table. It seems that json_normalize should be the function to make that happen but I can't figure out how.
import pandas
URL = 'https://statsapi.mlb.com/api/v1.1/game/642186/feed/live'
df = pandas.read_json(URL)
df2=pandas.json_normalize(df,record_path="liveData")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
