Arun
Arun

Reputation: 55

jq returns null when executed from linux commandline

I have a json text as below

{
  "_links": {
    "self": {
      "href": "http://xxx:8080/info"
    }
  },
  "build": {
    "name": "xxxx",
    "version": "2.0.23-69",
    "description": "xxxx"
  }
}

iam trying to get the version from the above json by using the below command

cat info.txt|jq  .version

but this is returning null. how can i get the version as 2.0.23-69

Upvotes: 0

Views: 1185

Answers (1)

peak
peak

Reputation: 116880

.version is inside .build, so the direct approach would be to write: .build | .version, or .build.version for short.

If in general you don't know exactly where the object of interest lives, you can also use the .. filter, e.g. .. | objects | .version // empty.

Upvotes: 1

Related Questions