Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a JSON file to variables with the windows command line?

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?

like image 772
Kriem Avatar asked Oct 14 '13 08:10

Kriem


Video Answer


1 Answers

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.

like image 68
Idan Arye Avatar answered Oct 24 '22 16:10

Idan Arye