json format each object in a line json format each object in a line json json

json format each object in a line


Per the jq manual

  • --compact-output / -c:

    By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line.

Therefore the following should work:

cat 2.txt | ./jq -c '{(.id): .custom}'