在下面的示例 json 中,我只需要提取 Parameter_1、Parameter_2 等的第二次出现,而不是第一次,任何人都可以帮助我吗
{
"response" :
[
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "Pune",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
},
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "250",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
}
]
}
预期结果集:
{
"response" :
[
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "250",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
}
]
}
为此使用 JSON_TRANSFORM (docs),在您的情况下,KEEP 操作可以解决问题:
with json_doc AS
(SELECT
'{
"response" :
[
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "Pune",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
},
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "250",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
}
]
}' AS json_data FROM dual
)
SELECT JSON_TRANSFORM(json_data, KEEP '$.response[1]' RETURNING CLOB PRETTY ) AS modified_json FROM json_doc
MODIFIED_JSON
--------------------------------------------------------------------------------
{
"response" :
[
{
"Parameter_1" : "high",
"Parameter_2" : 100,
"Parameter_3" : "",
"Parameter_4" : null,
"Parameter_5" : "250",
"address" :
{
"address" :
[
"India"
]
},
"addressElements" :
{
"Parameter_11" : null,
"Parameter_12" : "250",
"Parameter_13" : null,
"Parameter_14" : null,
"Parameter_15" : "India",
"Parameter_16" : "LN",
"Parameter_17" : null,
"Parameter_18" : null,
"Parameter_19" : null,
"Parameter_20" : null
}
}
]
}