-1

I want to produce a custom json line and display it together with another. I can only display one json line right now. I need to display the two sequentially. I'm adding property "index" to property "hits" with curl data.json | jq '{"index": {"index": {}}} + .hits.hits[]'

I've tried to pipe using jq '.index + ._source', but that just concatenates the property to _source. I've tried jq .index ._source, but that's an error.

I can select either _source or .index by piping the result jq ._source or jq .index. That will produce json lines correctly. That's fine. Now I need the .index, before each json line of ._source.

I need the result to look like this:

{"index": {}}
{/* ._source json line*/}
{"index": {}}
{/* ._source json line*/}
and so on...

Thank you!

Addibro
  • 107
  • 1
  • 8
  • This answer which does exactly that should help: https://stackoverflow.com/a/45604500/4604579 but use `.hits.hits[]` instead of `.[]` – Val Oct 09 '19 at 13:56
  • my bad @Val, missed that one – Addibro Oct 09 '19 at 14:06
  • Please fix the question in accordance with the [mcve] guidelines. In particular, a valid JSON text that is representative of the input to jq would be helpful, along with the corresponding expected result. – peak Oct 09 '19 at 15:03

1 Answers1

-1

I got it. Using jq '.index,._source' did the trick.

Addibro
  • 107
  • 1
  • 8