Home > OS >  While querying a json file from groovy getting null response
While querying a json file from groovy getting null response

Time:01-18

I am using below snippet in my jenking groovy file, where I am getting null response.

def Services= sh(script: "curl -s --header \"PRIVATE-TOKEN: ${gittoken}\" ${url}| jq -r .${Servicename}[]", returnStdout: true)

file which I am downloading is like below.

{
  "FrameWork1": [
    "sample/sample1",
    "sample/sample2"
  ]
 
}

Basically I am getting values of Framework1

if I give below one I am getting the first value of Framework object

Working one:###############

def Services= sh(script: "curl -s --header \"PRIVATE-TOKEN: ${gittoken}\" ${url}| jq -r .${Servicename}[1]", returnStdout: true)

CodePudding user response:

jq filter should be .FrameWork1[] to get a list of strings

https://jqplay.org/s/3iCv-off4ep

CodePudding user response:

Don't use shell parameter expansion to generate the jq program, pass the shell parameters as arguments to jq instead (then you do not have to worry about contexts, quoting, escaping, etc.)

... | jq -r --arg svc "$Servicename" '.[$svc][]'
  • Related