jq'。'使用jq将格式化的json文件恢复为原始json格式

时间:2017-06-29 13:36:11

标签: json bash jq jsonlines

这是我的json:

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

我希望它恢复原来的json格式:

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

如何使用jq来做到这一点? :)谢谢!

1 个答案:

答案 0 :(得分:7)

只需使用--compact-output / -c选项:

cat file | jq -c

(或者,没有猫科动物滥用:jq -c '.' file