前提・実現したいこと
ネストされた以下のようなJSONをCSVに変換したいのですが、いろいろ試してみたものの、どう扱っても上手く処理できません。
どなたか変換する方法をご教授頂けないでしょうか。
JSON
1{ 2 "masterNumber": 10000, 3 "code": "m-001", 4 "customerData": { 5 "name": "Jiro", 6 "age": 45 7 }, 8 "Address": [{ 9 "name": "testAreport", 10 "email": "tA@sample.co.jp" 11 }], 12 "items": [{ 13 "itemId": "item01", 14 "itemName": "商品01" 15 }, 16 { 17 "itemId": "item02", 18 "itemName": "商品02" 19 }, 20 { 21 "itemId": "item03", 22 "itemName": "商品03" 23 }] 24}
csv
1"masterNumber","code","customerData__name","customerData__age","Address__name","Address__email","items__itemId","items__itemName" 2"10000","m-001","Jiro","45","testAreport","tA@sample.co.jp","item01","商品01" 3"","","","","","","item02","商品02" 4"","","","","","","item03","商品03"
試したこと
json_normalizeというモジュールを使ってみたのですが、期待する結果のように変換できませんでした。
Python
1import json 2from pandas.io.json import json_normalize #package for flattening json in pandas df 3 4sample_object = {'Name':'John', 'Location':{'City':'Los Angeles','State':'CA'}} 5json_normalize(sample_object)