Search code examples
jsonjqjsonlinesndjson

jq filter to transform jsonlines into a single json map


Input:

{"aa":["a1","a2"]}
{"bb":["a1","b2"]}

Wanted output (no worries about potentially duplicate keys):

{
  "aa":["a1","a2"],
  "bb":["b1","b2"]
}

Many thanks!


Solution

  • The simplest would undoubtedly be to use the invocation:

    jq -s add
    

    If the input stream is extremely large, it might be better to use reduction, e.g.:

    jq -n 'reduce inputs as $i ({}; . + $i)'