Reputation: 1
I have a following json
{
"kind":"testObject",
"spec":{
},
"status":{
"code":"503"
}
}
I would like to just retrieve the value of code, so that it would just show 503
as an output.
I did try with JMESPath, but that binary is out of question, and not sure what to use.
Upvotes: 0
Views: 65
Reputation: 116640
Since this question has the jmespath tag, it is worth pointing out that one could use the JMESPATH command-line tool, jp, as follows:
jp status.code
or to suppress the quotation marks:
jp -u status.code
Similarly, using jaq, which has a jq-based syntax, one could write:
jaq .status.code
or to suppress the quotation marks:
jaq -r .status.code
Upvotes: 1
Reputation: 265131
Access the value with .status.code
:
$ jq '.status.code' <<JSON
{
"kind":"testObject",
"spec":{
},
"status":{
"code":"503"
}
}
JSON
"503"
If you want your output to be 503
(as compared to "503"
), use --raw-output
/-r
:
$ jq -r '.status.code' <<JSON
{
"kind":"testObject",
"spec":{
},
"status":{
"code":"503"
}
}
JSON
503
Upvotes: 1