JQ filtering on fields in nested Objects JQ filtering on fields in nested Objects json json

JQ filtering on fields in nested Objects


  1. The output "without commas" is a stream of JSON; to emit an array, wrap your jq filter in square brackets.
  2. You can abbreviate {id: id, type: .type} to {id, type}
  3. Your filter which repeats .batter[] has the effect of creating a Cartesian product. What you evidently wantinstead is to expand .batter just once.

Putting everything together:

[{id, type} + (.batter[] | {batterId: .id, batterType: .type})]