简体   繁体   English

使用Shell脚本解析JSON

[英]parse JSON using shell script

I need to parse JSON using shell script (I used to use Python, but not allowed in this specific environment), in this example, I want to get the value of b1 , which is 6.5 , anyone have any experience? 我需要使用shell脚本(我曾经使用Python,但在此特定环境中不允许使用)来解析JSON,在此示例中,我想获取b1的值(即6.5 ,任何人都有经验吗?

Using Linux/Mac OSX. 使用Linux / Mac OSX。

{
    "value": {
        "a1": {
            "amount": "5.5",
            "currency": "USD"
        },
        "b1": {
            "amount": "6.5",
            "currency": "USD"
        },
        "c1": {
            "d1": {
                "amount": "7.5",
                "currency": "USD"
            },
            "e1": {
                "amount": "8.5",
                "currency": "USD"
            },
            "f1": {
                "amount": "9.5",
                "currency": "USD"
            }
        },
        "g1": {
            "amount": "10.5",
            "currency": "USD"
        },
    }
}

Use jsawk: 使用jsawk:

curl -Ls http://github.com/micha/jsawk/raw/master/jsawk > jsawk curl -Ls http://github.com/micha/jsawk/raw/master/jsawk > jsawk

bash jsawk < /tmp/my_data.json 'return this.value.b1.amount' bash jsawk </tmp/my_data.json'返回this.value.b1.amount'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM