当变量具有特殊字符时如何使用jq [英] How to use jq when the variable has special characters

查看:80
本文介绍了当变量具有特殊字符时如何使用jq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使以下内容能够正常工作&不是,请帮帮我:

I'm trying to get the following to work & it's not, help me please:

curl -s 'https://cryptofresh.com/api/asset/markets?asset=MKR' | jq .OPEN.BTC

有问题的变量包含一个句点,我几乎尝试了一切以逃避句点&&还尝试将其用引号引起来;不行;这是我要从中提取的变量(我在运行jq时没有任何过滤器,并在此处截断了输出以显示我的需要.在此先感谢以后的问题解决者!

The variable in question includes a period, I tried just about everything to escape the period && also tried surrounding it in quotes; no go ; this is the variable I'm looking to pull from (I ran jq without any filters, and truncated the output here to show what I need. Thanks in advance future problem solver!

curl -s 'https://cryptofresh.com/api/asset/markets?asset=MKR' | jq
....
 "OPEN.BTC": {
"volume24": 0.932166,
"price": 0.09995,
"updated": "2016-05-04T03:03:29.000Z"
},
....

推荐答案

当键包含对标识符无效的字符时,您必须引用该名称.

When a key contains characters that are invalid for identifiers, you'll have to quote the name.

."OPEN.BTC"

或者对于旧版本的jq,使用索引.

Or for older versions of jq, use an index.

.["OPEN.BTC"]

这篇关于当变量具有特殊字符时如何使用jq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆