I´m using jq but having "-" in my json tag make jq not compile. I cannot escape it to make it works. Here the command
curl -X GET -H "X-AppKey:foo" "foo/v2/_status" | jq '.component-status[]'
I´ve read in the github of jq this post https://github.com/stedolan/jq/issues/202 but I cannot make it works.
This is the output of the curl
{ "status": "ok", "hostname": "0b0b495a46db", "component-status": [ { "status-code": 200, "component": "Service1", "status": "OK" }, { "status-code": 200, "component": "Service2", "status": "OK" } ] }
Any idea?
Currently, if the key name in a json key/value pair contains a special character (e.g. periods/dots, colons, hyphens) the data pills are broken as a result and the core use case of using Workato to pass data between steps is broken.
Passing arguments to JQ is done with --arg <name> <value> as shown below. Inside the filter, you can access a --arg with $<name> . In this case $foo returns bar . Note also in this example the -n flag which is used to tell JQ to not expect any JSON input.
jq is an amazing little command line utility for working with JSON data. We've written before about how you can use jq to parse JSON on the command line, but in this post I want to talk about using jq to create JSON data from scratch or make changes to existing data.
jq is a free open source JSON processor that is flexible and straightforward to use. It allows users to display a JSON file using standard formatting, or to retrieve certain records or attribute-value pairs from it.
You need to enclose in brackets and double quotes:
jq '."component-status"'
With your given input it returns:
[ { "status": "OK", "component": "Service1", "status-code": 200 }, { "status": "OK", "component": "Service2", "status-code": 200 } ]
The jq Manual (development) --> Basic filters:
.foo, .foo.bar
The simplest useful filter is
.foo
. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key “foo”, or null if there’s none present.If the key contains special characters, you need to surround it with double quotes like this:
."foo$"
.
From the github issue Cannot select field if field name has dashes:
Currently, that gets parsed as a subtraction. You can always explicitly use strings for when your keys don't fit identifier syntax.
The option suggested by rjurney or the commenters to his answers did not work for me (probably because I used PowerShell), however in the answer from github issue there was a solution, which did the trick - escaping double quotation marks with \
jq '.\"component-status\"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With