【问题标题】:jq '.' formatted json file back to original json format using jqjq'。使用 jq 将格式化的 json 文件恢复为原始 json 格式
【发布时间】:2017-06-29 13:36:10
【问题描述】:

这是我的 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 来做到这一点? :) 谢谢!

【问题讨论】:

  • 定义“原创”。如果格式不同,您传递给 jq 的 Json 可能会发生变化。你会丢失你可能拥有的奇数空白,数字的精度可能会改变等等。有了这些,就不可能恢复输入的“原始”格式,它都会被规范化。

标签: json bash jq jsonlines


【解决方案1】:

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

cat file | jq -c

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

【讨论】:

  • < file jq -c .
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-07
  • 1970-01-01
  • 2021-03-10
  • 2017-01-01
  • 1970-01-01
相关资源
最近更新 更多