jq不使用密钥,包括破折号

时间:2018-01-23 06:56:19

标签: syntax jq

我有一个REST API,它返回如下内容:

jq: error (at <stdin>:1): null (null) and boolean (true) cannot be subtracted

当我做`http / endpoint / url |时jq'.foo-bar',它给出了以下错误:

jq

看起来foo-bar认为我正在尝试使用img_view.layer.superlayer?.insertSublayer(pulsator, below: img_view.layer) 进行算术运算。

我如何正确地形成这种路径?或者这是jq的错误?

1 个答案:

答案 0 :(得分:0)

在JSON文本中,JSON键始终双引号。也许您的REST API在双引号中正确格式化,并且您上次编辑中的示例不正确。因为没有相同的jq无法将语法解析为有效的JSON。

就您所看到的问题而言,您需要将该字段放在引号内,让jq知道您正在访问的是单个字段foo-bar,而不是单独的字段

jq '."foo-bar"'

或者更具体地说,将数组访问运算符用作jq '.["foo-bar"]'