Hey community,
I have run into an issue that gives me a mild headache. I am quite sure I am missing something basic but I cannot identify it.
Background: I have read up an API response that looks like this:
{
"id": 27653,
"name": "System",
"color": "G200",
"editable": true
},
{
"id": 27654,
"name": "Completeness",
"color": "#36B37E",
"editable": true
},
{
"id": 27655,
"name": "Application",
"color": "R400",
"editable": true
},
What I need to do from here is to check if a block including a certain id exists. I have tried this:
{{webResponse.body.id.match("(27653)").size}}
which I expected should have returned 1, but it returns 0.
I have played around with the regex and found that is I match on another element in the block it works fine, like this:
{{webResponse.body.name.match("(Compl.*)").size}}
returns 1 as expected. So I am thinking that it has to do with the format of the two values, number and string.
Any ideas how to make this .match() function with the numeric attribute id?
Thnx in advance!
Cheers,
// Svante
Hi @Svante Gustafsson Björkegren
I wonder if the JSON parsing from the webResponse is detecting the type as number rather than text type. You could check that by forcing conversion to text with format() prior to the match() function:
{{webResponse.body.id.format("#").match("(27653)").size}}
Kind regards,
Bill
UPDATED: as the text function apparently does not work with number data.
Hi @Svante Gustafsson Björkegren
What if you would try the following.
{{#webResponse.body}}{{if(equals(id,"27653"), 1)}}{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.