我有一个嵌套的json文件,我需要从json文件中提取数据并使用postgresql存储在不同的表中。
Json文件:
{
"Master_Tables":[
{
"type":"Details",
"features":[
{
"id":"0001",
"type":"donut",
"name":"Cake",
"ppu":0.55,
"batters":{
"type":"batter",
"features":[
{
"id":"1001",
"type":"Regular"
},
{
"id":"1002",
"type":"Chocolate"
}
]
},
"toppings":{
"type":"toppings",
"features":[
{
"id":"5001",
"type":"None"
},
{
"id":"5002",
"type":"Glazed"
}
]
}
}
]
}
]
}
我尝试了没有嵌套,我能够得到。但是有了嵌套,我无法做到。我将所有记录保存在一个表“ Details”中
我尝试不嵌套的代码:
select
cast(json_array_elements(jsonData::json->'Master_Tables')::json -> 'type' as character varying) as table_name,
json_array_elements(jsonData::json->'Master_Tables')::json -> 'features' as data
from "Incoming_json_Test"
注意:“ Incoming_json_Test”具有文本格式的Json文件。
我希望输出为3个不同的行,其中表名和json_data位于表的2个不同列中。
输出格式,我没有嵌套是 O/P : without nesting