JQ issues with comments on Json file

吃可爱长大的小学妹 提交于 2020-05-29 05:14:55

问题


I'm using JQ https://stedolan.github.io/jq/ to work in bash with my json and when I read the json is throwing me an error

   parse error: Invalid numeric literal at line 2, column 5=

Since my json has some comments

  // comment
  "spawn": {}

I've been seen looking the options and I cannot find any option to fix the problem. Any idea how to solve it?


回答1:


JSON and thus jq do not support comments (in the usual sense) in JSON input. The jq FAQ lists a number of tools that can be used to remove comments, including jsonlint, json5, and any-json. I'd recommend one that can act as a filter.

See https://github.com/stedolan/jq/wiki/FAQ#processing-not-quite-valid-json for links and further details.




回答2:


Remove them; JSON does not support comments.

(JSON is defined here; you can see a briefer description of the grammar here.)




回答3:


I found https://github.com/sindresorhus/strip-json-comments-cli which allows you to do:

cat my_json_with_comments.json | strip-json-comments | jq  .


来源:https://stackoverflow.com/questions/33352930/jq-issues-with-comments-on-json-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!