Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

json - How to use jq when the variable has reserved characters?

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

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

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"
},
....
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

."OPEN.BTC"

Or for older versions of jq, use an index.

.["OPEN.BTC"]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...