How to use jq when the variable has special characters

前端 未结 2 1641
生来不讨喜
生来不讨喜 2020-11-29 11:22

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


        
相关标签:
2条回答
  • 2020-11-29 11:55

    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"]
    
    0 讨论(0)
  • 2020-11-29 11:56

    Another answer didn't work for me but the comment written by @jeff-mercado worked for me. So, adding it as an answer here.

    If your key has dots like "OPEN.BTC" then your jq command should be

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

    Put the key first in double quotes and then escape the first dot by wrapping it using single quotes.

    0 讨论(0)
提交回复
热议问题