3

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!

peak
  • 105,803
  • 17
  • 152
  • 177
Eleanor
  • 2,647
  • 5
  • 18
  • 30
  • Define "original." Json you pass in to jq is subject to change if they're formatted differently. You'll lose odd whitespacing you may have, precision of numbers may change, etc. With those, it will be impossible to get back the "original" formatting of the input, it will all be normalized. – Jeff Mercado Jun 29 '17 at 16:50

1 Answers1

9

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

cat file | jq -c

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

randomir
  • 17,989
  • 1
  • 40
  • 55