Search code examples
jsonbashjqjsonlines

jq '.' formatted json file back to original json format using jq


Here is my json:

[
 {
  "ReferringUrl": "N",
  "OpenAccess": "0",
  "ItmId": "1694738780"
 },
 {
  "ReferringUrl": "L",
  "OpenAccess": "1",
  "ItmId": "1347809133"
 }
]

I want it back to the original json format:

[{"ReferringUrl": "N","OpenAccess": "0","ItmId": "1694738780"},{"ReferringUrl": "L","OpenAccess": "1","ItmId": "1347809133"}]

How to use jq to do this? :) Thank you!


Solution

  • Just use the --compact-output / -c option:

    cat file | jq -c
    

    (or, without feline abuse: jq -c '.' file)