eagle
eagle

Reputation: 890

Parse JSON string within JSON and other fields

I have a file in s3 which when unzipped has something of this format

{"a": "foo",
 "b": "bar",
 "c": : "{\"hello\": \"world\"}"}

Now I know I can parse the value of c by doing jq '.c | fromjson | .hello'

But let's say I want all the values from this json, a, b, and c. This is the code snippet I currently have:

aws s3 cp s3://somebucket/somekey.gz - | gunzip | jq '[.a, .b]'

How do I incorporate grabbing the value from c into this expression?

Upvotes: 7

Views: 3265

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92894

I want all the values from this json, a, b, and c

jq solution for valid JSON structure:

... | jq '[.a, .b, (.c | fromjson | .[])]'
  • .[] - returns all the values of the array/object

The output:

[
  "foo",
  "bar",
  "world"
]

Upvotes: 9

Related Questions