Using Substring Between to parse an id from a JSON response body

Brian Gauthier October 4, 2024

I have a JSON response body that contains an id within a web request that I previously called for .  I'm attempting to use the substring between to fetch the ID, but it's unsuccessful at finding it.   The substring I'm using is 

I'm trying to extract the number 357636

FindID: 

{{webhookResponse.body.substringBetween("id=", ",")}}

 

 

The JSON response was

 

{queryType=flat, queryResultType=workItem, asOf=2024-10-04T19:26:34.07Z, columns=[{referenceName=System.Id, name=ID, url=https://abc.com/123/_apis/wit/fields/System.Id}, {referenceName=System.Title, name=Title, url=https://abc.com/123/_apis/wit/fields/System.Title}], workItems=[{id=357636, url=https://abc.com/123/2049fc05-e304-4422-b2be-d7c00d1f17d5/_apis/wit/workItems/357636}]}

1 answer

0 votes
Jim Knepley - ReleaseTEAM
Atlassian Partner
October 4, 2024

I would try to use match() instead:

{{webhookResponse.body.body.match(".*id=([0-9]+).*")}}

ref: https://community.atlassian.com/t5/Jira-questions/Use-result-of-match-function-in-smart-value-branching-for-each/qaq-p/2014379

Brian Gauthier October 5, 2024

Gave it a shot and still didn't work.  Any other function that I could use to test?  I've also tried 

SearchforID:{{webhookResponse.body.substringAfter("id=").substringBefore(",")}}
Brian Gauthier October 5, 2024

To be honest, I'm having trouble parsing anything from that JSON body

Jim Knepley - ReleaseTEAM
Atlassian Partner
October 7, 2024

Trying to use structured text by treating it as a string is always tricky, it's better to parse it properly, but that's not an option within smart values that I know of.

A JSON parsing package is part of Groovy (groovy.json.JsonSlurper). You might have an easier time using ScriptRunner.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events