How to parse a JSON file to variables with the win

2020-02-26 09:54发布

I have this JSON file called test.json which says:

{
    "test":true,
    "limit": 
    {
        "min":0.5,
        "max":1.5
    }
}

I'd like to be able to read this file in the Windows command line and have these objects parsed as variables.

How would I do this?

1条回答
啃猪蹄的小仙女
2楼-- · 2020-02-26 10:41

If you use Windows Powershell as your command line, you can use the ConvertFrom-JSON cmdlet: http://powershelljson.codeplex.com/

Make sure your PowerShell version is above 3.0, as ConvertFrom-JSON is available from that version.

If you use plain old CMD, you'll need an external tool for it. I like jq: http://stedolan.github.io/jq/. The tutorial uses curl for the examples, but you can just as easily use echo or read the JSON from a file.

查看更多
登录 后发表回答