Home > database >  Windows version fails where jqplay.org works
Windows version fails where jqplay.org works

Time:03-04

I've been using jq to parse the output from AWS cli.

The output looks something like this..

{
"Vpcs": [
    {
        "CidrBlock": "10.29.19.64/26",
        "State": "available",
        "VpcId": "vpc-0ba51bd29c41d41",
        "IsDefault": false,
        "Tags": [
            {
                "Key": "Name",
                "Value": "CloudEndure-Europe-Development"
            }
        ]
    }
]}

and the script I am using looks like this..

.Vpcs[] | [.VpcId, .CidrBlock,   (.Tags[]|select(.Key=="Name")|.Value)]

If I run it under Windows it fails like this.

jq: error: Name/0 is not defined at , line 1: .Vpcs[] | [.VpcId, .CidrBlock, (.Tags[]|select(.Key==Name)|.Value)] jq: 1 compile error

But it works fine in jqplay.org.

Any ideas, on Windows Im using jq-1.6.

Thanks

Bruce.

CodePudding user response:

The correct jq program is

.Vpcs[] | [.VpcId, .CidrBlock, ( .Tags[] | select( .Key == "Name" ) | .Value ) ]

You didn't show the command you used, but you provided the following to jq:

.Vpcs[] | [.VpcId, .CidrBlock, ( .Tags[] | select( .Key == Name ) | .Value ) ]

That's incorrect. (Notice the missing quotes.)

Not only did you not provide what command you used, you didn't specify whether it was being provided to the Windows API (CreateProcess), Windows Shell (cmd) or Power Shell.

I'm guessing cmd. The following should work for cmd:

jq ".Vpcs[] | [.VpcId, .CidrBlock, ( .Tags[] | select( .Key == \"Name\" ) | .Value ) ]" file.json

CodePudding user response:

I'm not agreeing to ikegami about the CMD command that [he/she?] provided because the character used for CMD escaping is ^, not \ like Assembly/C/C . I hope this will work (I don't want to test this on my potato thing):

jq .Vpcs[] | [.VpcId, .CidrBlock, ( .Tags[] | select( .Key == "Name" ) | .Value ) ] file.json

or this:

jq .Vpcs[] | [.VpcId, .CidrBlock, ( .Tags[] | select( .Key == ^"Name^" ) | .Value ) ] file.json
  • Related