Posts

Showing posts with the label jq

jq error while parsing json file inside jenkins Shell

jq error while parsing json file inside jenkins Shell I want to parse the value of the filepath from the json. while parsing it via jq and seeing issue with respect to not defined at top level. Please find the json details and the error below: "environment":{ "stage":{ "testing":[ { "tag":"1.0" "filepath":"C:/test/conf" "hostname":"test" }]}} **command Used in Execute shell:** jq -r ".'environment.stage.testing.filePath' env.json **Error Faced**: jq: error: environments/0 is not defined at <top-level>, line 1: environment.stage.testing.filePath jq: 1 compile error TIA 2 Answers 2 The posted data conforms with the requirements of HJSON, and can be converted to JSON by: hjson -j The jq filter includes .filePath whereas the HJSON only includes a key n...

Reporting every (optional) subelement

Reporting every (optional) subelement Want to parse the following: { "issues": [ { "id": "1", "fields": { "links": } }, { "id": "2", "fields": { "links": [ { "inlink": { "id": "red" } } ] } }, { "id": "3", "fields": { "links": [ { "outlink": { "id": "yellow" } } ] } }, { "id": "4", "fields": { "links": [ { "inlink": { "id": "green" } }, { "outlink": { "id": "blue" } } ] } } ] } into elements that represent the links elements, one for one, like this (note that id 1 is missing and id 4 appears twice: links id 1 id 4 { "id": "2", "link": { "linktype": "inlink", "id": "red" } }, { "id": "3...