I'm trying to import some data from an API that has an unusual nested JSON structure. Here's a snippet of what the JSON data looks like:
{"series":[{"series_id":"NG.N9010US2.M","name":"U.S. Natural Gas Gross Withdrawals, Monthly","units":"Million Cubic Feet","f":"M","unitsshort":"MMcf","description":"U.S. Natural Gas Gross Withdrawals","copyright":"None","source":"EIA, U.S. Energy Information Administration","iso3166":"USA","geography":"USA","start":"197301","end":"202112","updated":"2022-02-28T17:53:37-0500","data":[["202112",3683216],["202111",3551244],["202110",3595255],["202109",3412770],["202108",3530753],["202107",3490995],["202106",3391187],["202105",3510356],["202104",3408930],["202103",3482323],["202102",2923896],["202101",3506258],["202012",3489506],["202011",3352374],["202010",3363756],["202009",3265272],["202008",3349817],["202007",3373594],["202006",3217496],["202005",3285105],["202004",3374224],["202003",3582414],["202002",3363434],["202001",3596775],["201912",3622512],["201911",3509293],["201910",3551970],["201909",3396571],["201908",3448106],["201907",3395984],["201906",3299794],["201905",3424018],["201904",3315270],["201903",3383042],["201902",3056916],["201901",3376735],["201812",3391473],["201811",3259912],["201810",3314676],["201809",3153978],["201808",3206177],["201807",3138242],["201806",2972738],["201805",3098558],["201804",2976108],["201803",3069284],["201802",2751215],["201801",2993178],["201712",3025419],["201711",2897003],["201710",2911373],["201709",2763285],["201708",2769670],["201707",2753997],["201706",2688422],["201705",2778965],["201704",2689967],["201703",2797117],["201702",2493267],["201701",2723628]]}
I'm not very familiar with different flavors of JSON. As you can see, the data is nested within the series information, but it's not in the typical paired format. I have been able to import the data as a nested list using fromJSON in the jsonlite package, but I'm stuck on how to convert it into a data frame. I would like the series information to be maintained with a new row for each pair of data observations.
I haven't gotten very far with this, so my code so far is pretty simple. I was able to extract the data series as a list using the $ operator:
gas <- fromJSON("gas production.json", flatten=TRUE)
gas$series$data
Thanks!