7

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?

2
  • 1
    Is your JSON valid? It needs to have a bracket present "c": ["{\"hello\": \"world\"}"] Commented Jan 30, 2018 at 17:10
  • "c": : " is definitely not valid JSON. Please test your example data to make sure it's genuinely representative of the input format. Commented Jan 30, 2018 at 17:26

1 Answer 1

9

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"
]
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.