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년 전1746회 조회
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠