3

JSON data as below

{name : Mike, job : [{name: abc, value: 123},{name: def,value: 456}]}

How to retrieve the value of name = abc and def?

EDIT:(SOLUTION) Got the solution myself thanks

 WITH x AS (
SELECT parse_json('{"name" : "Mike", "job" : [{"name": "abc", "value": "123"},{"name": "def","value": "456"}]}' ) as payload_json)
    select x.payload_json:name,
           job.value:name::varchar as name,
           job.value:value::varchar as value
     from x,
    lateral flatten( input => x.payload_json:job, outer => true) as job;

1 Answer 1

3

I got the answer myself as below

 WITH x AS (
SELECT parse_json('{"name" : "Mike", "job" : [{"name": "abc", "value": "123"},{"name": "def","value": "456"}]}' ) as payload_json)
    select x.payload_json:name,
           job.value:name::varchar as name,
           job.value:value::varchar as value
     from x,
    lateral flatten( input => x.payload_json:job, outer => true) as job;
Sign up to request clarification or add additional context in comments.

1 Comment

Feel free to tag your own answer as the correct one!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.