1

I have an object that is just a bunch of arbitrary keys with each an array:

{
  "foo": [
    "hello",
    "world"
  ],
  "bar": [
    "foobar"
  ]
}

How can I return the merged arrays in this object. The expected output would be:

[
  "hello",
  "world",
  "foobar"
]
1
  • Are you concerned with uniqeness? Can't you just use concat? Commented Dec 3, 2018 at 21:35

2 Answers 2

3

Create a list of the values and concatenate the elements in that list:

[.[]] | add

Create a list of each element in each array:

[.[][]]

I'd prefer the first one since it parses easier in my mind.

Sign up to request clarification or add additional context in comments.

Comments

1

Generalizing a bit:

jq '[..|scalars]' input.json

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.