Extract key Value pair from a column value which is a Json structure

0

Hi All,
Your help on this will be appreciated.

I have a table like

3 columns -> _ID || Col_A || Col_B

Col_A values is as :
"{
""FIELDS"" : [ ""Fruits"" ],
""MAP"" : {
""101"" : ""APPLE"",
""102"" : ""BANANA"",
""103"" : ""ORANGE"",
""104"" : ""PINEAPPLE"",
""105"" : ""APRICOTS"",
""VOG"" : ""COCONUT"",
""VOT"" : ""BERRY""
},
""TYPE"" : ""MAP"",
""updatedAt"" : ""Wed Sep 11 10:12:11 UTC 2019"",
""updatedBy"" : ""Mark""
}"

I want to extract the values from Col_A as
ID || Name

101 || APPLE
102 || BANANA
103 || ORANGE
104 || PINEAPPLE
105 || APRICOTS
VOG || COCONUT
VOT || BERRY

已提問 5 年前檢視次數 1735 次
1 個回答
0

got the solution to this.

  1. inner query to extract data from Jason structure.. specific array

  2. un nesting both the keys and value pair form the structure. check the syntax

SELECT
DISTINCT m.key AS PROGRAMID,TRIM(UPPER(CAST(m.value AS VARCHAR)))AS PROGRAM
from
(SELECT json_extract(programidudf, '$.MAP') as Program_jason
FROM "tableaureports"."global_udf_parquet" where programidudf is not null)
CROSS JOIN
UNNEST
(
(map_keys(CAST(CAST(Program_jason AS JSON) AS map<varchar,json>))) ,
(map_values(CAST(CAST(Program_jason AS JSON) AS map<varchar,json>)))
)
AS m(key,value)

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南