0

I have neted JSON data like:

{"body":{"metrics":[{"a":1,"a1":1.1,"properties":{"propA":"name","propB":"age"}},{"b":2}]}}
{"body":{"metrics":[{"c":3}]}}

I can use select get_json_object(get_json_object(columnA,'$.Body'),'$.metrics') from... to extracted nested json arrays like:

[{"a":1,"a1":1.1,"a2":{"propA":"name","propB":"age"}},{"b":2}]
[{"c":3}]

I want to convert them into rows like:

{"a":1,"a1":1.1,"a2":{"propA":"name","propB":"age"}}
{"b":2}
{"c":3}

It seems the array returned by get_json_object is string and when I use later view it always says: UDFArgumentException explode() takes an array or a map as a parameter

Length of each array is uncertain and I do not have permit to upload jar files to active new udf or serde clases. How to achieve this...

2
  • Are you saying that this is STRING: [{"a":1},{"b":2}] ? Commented Jun 22, 2020 at 11:30
  • @leftjoin Thanks for your reply. I'm not sure... It's returned by get_json_object and it looks like string.. Or do you have any better idea? Btw, I just modified the original question post. Commented Jun 22, 2020 at 11:32

1 Answer 1

2

Say your json is in a table test. You can use below query to get the desired output:

select m.* from test s
LATERAL view explode(split(regexp_replace(get_json_object(value,'$.body.metrics'),'^\\[|]$',''), ',(?!")')) m
Sign up to request clarification or add additional context in comments.

Comments

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.