これは私がPythonでそれをしなければならなかったときに私がしたことです:(完全ではありませんが、後で実践のためにjavascriptでそれを試みます。)再帰の概念がこれではるかに明確であるため、私はそれを投稿しました。
#Builds the names and makes a nested list with {"table.hierarchy.id":value} pairs:
def undic(dic,levs=0,tmp=""):
if(isinstance(dic,dict)):
return([undic(dic[d],levs=levs+1,tmp=tmp+d+".") for d in dic.keys()])
else:
return {tmp : dic}
#Flattens the list to something we can easilly work with:
def flat_content(dic):
ll=undic(dic)
if(isinstance(ll[0],dict)):
return(ll)
return(reduce(lambda x,y:x+y,ll))
次に、一意の列名を見つけて、階層の0番目のレベルから行名を保持し、欠落しているキーなどを処理するユーティリティ関数を作成します(.update({"missingKey": ""}で実行しました)。素敵な小さなjsonからテーブルへのコンバーター(CSVに簡単にキャストできます)!
ただし、質問のjsonは表示されません。