Json processing with a selection

Hi,

working on a complex json response and wanted to use the selection tools in json.

{"matches":[{"id":"2022WCWin","name":"2022 World Cup Winner+-","backendId":"2022WCWin","backendUniqueId":482138,"competitionbackendId":"7490","round":null,"broadcastChannel":null,"broadcastChannels":[],"startTime":"2022-06-01T13:00:00.000Z","_links":{"self":"https://uat02.beta.company.com.au/v1/company-info-service/sports/Soccer/competitions/2022%20World-%20Cup%2B%20Futures/matches/2022%20World%20Cup%20Winner%2B-?jurisdiction=NSW","selfTemplate":"https://uat02.beta.company.com.au/v1/company-info-service/sports/Soccer/competitions/2022%20World-%20Cup%2B%20Futures/matches/2022%20World%20Cup%20Winner%2B-?jurisdiction={jurisdiction}{&channelType,cashSales,homeState}","markets":"https://uat02.beta.company.com.au/v1/company-info-service/sports/Soccer/competitions/2022%20World-%20Cup%2B%20Futures/matches/2022%20World%20Cup%20Winner%2B-/markets?jurisdiction=NSW"},"contestants":[],"competitors":[],"openMarketCount":1,"futureMarketCount":1,"nonFutureMarketCount":0,"markets":[{"id":"25692111","name":"2022 World Cup Winner 21/11","shortName":"2022 World Cup Winner","betOption":"Winner","betOptionbackendId":"52","betOptionPriority":85,"marketUniqueId":25692111,"closeTime":"2022-06-01T13:00:00.000Z","bettingStatus":"Open","message":"To win 2022 World Cup","informationMessage":"TEST asffshdf dfsfdsf t5s gdfsfdh ghdfhtfdhfd hsfdsfgsfsds ghsfdgsfgasf hgsdfwgdfgs hdffhfs  ghfdhfdh hgfsgffhfTEST TEST hbdgjgdjgdjagsjyysgdjgd hjgdgdghtgdgb jhgdgdgdg TEST","isFuture":true,"onlineBetting":true,"phoneBettingOnly":false,"inPlay":false,"goingInPlay":false,"allowWin":true,"allowPlace":false,"allowEachWay":false,"allowMulti":true,"allowMultiWin":true,"allowMultiPlace":false,"allowMultiEachWay":false,"numberOfPlaces":0,"cashOutEligibility":"Enabled","allowBundle":false,"propositions":[{"id":"288949","name":"Others on Request","returnWin":0,"returnPlace":0,"differential":null,"bettingStatus":"Suspended","allowPlace":false,"number":288949,"isOpen":false,"sortOrder":70},{"id":"288884","name":"Argentina","returnWin":12,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288884,"isOpen":true,"sortOrder":5},{"id":"288880","name":"Brazil","returnWin":17,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288880,"isOpen":true,"sortOrder":1},{"id":"288885","name":"Belgium","returnWin":18,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288885,"isOpen":true,"sortOrder":6},{"id":"288887","name":"Italy","returnWin":18,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288887,"isOpen":true,"sortOrder":8},{"id":"288882","name":"Germany","returnWin":19,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288882,"isOpen":true,"sortOrder":3},{"id":"288889","name":"Portugal","returnWin":19,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288889,"isOpen":true,"sortOrder":10},{"id":"288881","name":"France","returnWin":20,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288881,"isOpen":true,"sortOrder":2},{"id":"288883","name":"Spain","returnWin":20,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288883,"isOpen":true,"sortOrder":4},{"id":"288886","name":"England","returnWin":20,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288886,"isOpen":true,"sortOrder":7},{"id":"288888","name":"Netherlands","returnWin":20,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288888,"isOpen":true,"sortOrder":9},{"id":"288890","name":"Croatia","returnWin":41,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288890,"isOpen":true,"sortOrder":11},{"id":"288891","name":"Uruguay","returnWin":41,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288891,"isOpen":true,"sortOrder":12},{"id":"288892","name":"Colombia","returnWin":41,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288892,"isOpen":true,"sortOrder":13},{"id":"288893","name":"Chile","returnWin":51,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288893,"isOpen":true,"sortOrder":14},{"id":"288894","name":"Mexico","returnWin":67,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288894,"isOpen":true,"sortOrder":15},{"id":"288895","name":"Sweden","returnWin":101,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288895,"isOpen":true,"sortOrder":16},{"id":"288897","name":"Denmark","returnWin":101,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288897,"isOpen":true,"sortOrder":18},{"id":"288899","name":"Serbia","returnWin":101,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288899,"isOpen":true,"sortOrder":20},{"id":"288900","name":"Turkey","returnWin":101,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288900,"isOpen":true,"sortOrder":21},{"id":"288901","name":"Ukraine","returnWin":101,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288901,"isOpen":true,"sortOrder":22},{"id":"288896","name":"USA","returnWin":105,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288896,"isOpen":true,"sortOrder":17},{"id":"288898","name":"Paraguay","returnWin":106,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288898,"isOpen":true,"sortOrder":19},{"id":"288902","name":"Austria","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288902,"isOpen":true,"sortOrder":23},{"id":"288904","name":"Switzerland","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288904,"isOpen":true,"sortOrder":25},{"id":"288905","name":"Czech Republic","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288905,"isOpen":true,"sortOrder":26},{"id":"288906","name":"Poland","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288906,"isOpen":true,"sortOrder":27},{"id":"288907","name":"Bosnia Herzegovina","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288907,"isOpen":true,"sortOrder":28},{"id":"288908","name":"Qatar","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288908,"isOpen":true,"sortOrder":29},{"id":"288909","name":"Wales","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288909,"isOpen":true,"sortOrder":30},{"id":"288910","name":"Norway","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288910,"isOpen":true,"sortOrder":31},{"id":"288911","name":"Greece","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288911,"isOpen":true,"sortOrder":32},{"id":"288919","name":"Senegal","returnWin":151,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288919,"isOpen":true,"sortOrder":40},{"id":"288912","name":"Cameroon","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288912,"isOpen":true,"sortOrder":33},{"id":"288916","name":"Republic Of Ireland","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288916,"isOpen":true,"sortOrder":37},{"id":"288917","name":"Nigeria","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288917,"isOpen":true,"sortOrder":38},{"id":"288918","name":"Morocco","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288918,"isOpen":true,"sortOrder":39},{"id":"288920","name":"Japan","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288920,"isOpen":true,"sortOrder":41},{"id":"288924","name":"Ecuador","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288924,"isOpen":true,"sortOrder":45},{"id":"288927","name":"Peru","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288927,"isOpen":true,"sortOrder":48},{"id":"288929","name":"Slovakia","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288929,"isOpen":true,"sortOrder":50},{"id":"288930","name":"Slovenia","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288930,"isOpen":true,"sortOrder":51},{"id":"288931","name":"Australia","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288931,"isOpen":true,"sortOrder":52},{"id":"288932","name":"Tunisia","returnWin":201,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288932,"isOpen":true,"sortOrder":53},{"id":"288913","name":"Ghana","returnWin":205,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288913,"isOpen":true,"sortOrder":34},{"id":"288914","name":"Iceland","returnWin":210,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288914,"isOpen":true,"sortOrder":35},{"id":"288915","name":"Ivory Coast","returnWin":213,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288915,"isOpen":true,"sortOrder":36},{"id":"288921","name":"Algeria","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288921,"isOpen":true,"sortOrder":42},{"id":"288922","name":"Bulgaria","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288922,"isOpen":true,"sortOrder":43},{"id":"288923","name":"China","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288923,"isOpen":true,"sortOrder":44},{"id":"288925","name":"Egypt","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288925,"isOpen":true,"sortOrder":46},{"id":"288926","name":"Montenegro","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288926,"isOpen":true,"sortOrder":47},{"id":"288928","name":"Romania","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288928,"isOpen":true,"sortOrder":49},{"id":"288933","name":"South Korea","returnWin":251,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288933,"isOpen":true,"sortOrder":54},{"id":"288935","name":"Iran","returnWin":301,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288935,"isOpen":true,"sortOrder":56},{"id":"288936","name":"Scotland","returnWin":301,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288936,"isOpen":true,"sortOrder":57},{"id":"288937","name":"Costa Rica","returnWin":301,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288937,"isOpen":true,"sortOrder":58},{"id":"288934","name":"Israel","returnWin":501,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288934,"isOpen":true,"sortOrder":55},{"id":"288938","name":"Northern Ireland","returnWin":501,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288938,"isOpen":true,"sortOrder":59},{"id":"288939","name":"Cyprus","returnWin":751,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288939,"isOpen":true,"sortOrder":60},{"id":"288941","name":"Georgia","returnWin":751,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288941,"isOpen":true,"sortOrder":62},{"id":"288945","name":"Panama","returnWin":751,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288945,"isOpen":true,"sortOrder":66},{"id":"288947","name":"Saudi Arabia","returnWin":751,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288947,"isOpen":true,"sortOrder":68},{"id":"288940","name":"Finland","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288940,"isOpen":true,"sortOrder":61},{"id":"288942","name":"Honduras","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288942,"isOpen":true,"sortOrder":63},{"id":"288943","name":"Albania","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288943,"isOpen":true,"sortOrder":64},{"id":"288944","name":"Kosovo","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288944,"isOpen":true,"sortOrder":65},{"id":"288946","name":"South Africa","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288946,"isOpen":true,"sortOrder":67},{"id":"288948","name":"Canada","returnWin":1001,"returnPlace":0,"differential":null,"bettingStatus":"Open","allowPlace":false,"number":288948,"isOpen":true,"sortOrder":69}]}],"inPlay":false,"goingInPlay":false}],"betOptionPriority":["Winner"]}

I want select id’s where bettingStatus==“Open”.

In this website (http://jsonpath.herokuapp.com/?path=$..author) the following criteria works

$..matches[*].markets[*].propositions[?(@.bettingStatus== 'Open')].id

and i’ve been trying to use the same approach in k6 but getting nowhere fast.

    var urlResponseJson = urlResponse.json('$..matches[*].markets[*].propositions[?(@.bettingStatus=="Open")].id');
    console.log(urlResponseJson);
INFO[0001] urlResponseJson: undefined                    source=console

Any tips?

Hi @BobRuub !

k6 uses a different syntax for the JSON path. You can learn about it here GitHub - tidwall/gjson: Get JSON values quickly - JSON parser for Go.

For example, the for your task, the “ugly” version of the query will look like this:

const urlResponseJson = urlResponse.json('matches.#.markets.#.propositions.#(bettingStatus=="Open")#.id|@flatten|@flatten|@flatten');

console.log(urlResponseJson);

Hope that answers,
Cheers!

Thank you for the helpful link.