My jq command returns objects in brackets but without comma separators. But I would like to create a new json string from it.
This call finds all elements of arr>
You can always embed a stream of (zero or more) JSON entities within some other JSON structure by decorating the stream, that is, in the present case, by wrapping the STREAM as follows:
{ arr: [ STREAM ] }
In the present case, however, we can also take the view that we are simply editing the original document, and accordingly use a variation of the map(select(...))
idiom:
.arr |= map( select(index("FooItem")) | .[3].texts)
This latter approach ensures that the context of the "arr" key is preserved.
To filter out the empty strings, simply add another map(select(...))
:
.arr |= map( select(index("FooItem"))
| .[3].texts | map(select(length>0)))