Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to get an Array field from a Json content using Script runner in jira

serge calderara
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 06, 2020

Dear all,

I have a the following code whih return a Json response from an http request which is returned as below and is an Array of a single item ( The return data format is given from MSGraph Api ):


public String getGuestUserId(String AuthToken,String userEmail){

    String _userId
    def http = new HTTPBuilder(graph_base_user_url + "?")        http.request(GET) {            requestContentType = ContentType.JSON
            //uri.query = [ $filter:"mail eq '$userEmail'"].toString()            uri.query=[$filter:"mail eq '$userEmail'"]            headers.'Authorization' = "Bearer " + AuthToken    

            response.success = { resp, json ->                _userId=json["value"]

            // user ID not found : error 404            response.'404' = { resp ->       
                _userId = 'Not Found'

        }        _userId

The return json value is as below :

[{businessPhones=[], displayName=user test, givenName=null, jobTitle=null,, mobilePhone=null, officeLocation=null, preferredLanguage=null, 
surname=null,, id=7982c558- ba50-4380-9e94-114d8b340720}]

What I am trying to do from Script runner is to retrive only the Id member field


From the script console I have try to access it as below :

def ret =apiHelper.getGuestUserId(apiHelper.Token,email)

def json = new groovy.json.JsonSlurper().parseText ret

But is does not work and I get an exception as below:

 groovy.json.JsonException: expecting '}' or ',' but got current char 'b' with an int value of 98 The current character read is 'b' with an int value of 98 expecting '}' or ',' but got current char 'b' with an int value of 98 line number 1 index number 2 [{businessPhones=[], displayName=serge cal test, givenName=null, jobTitle=null,, mobilePhone=null, officeLocation=null, preferredLanguage=null, surname=null,, id=7982c558-ba50-4380-9e94-114d8b340720}] ..^ at org.apache.groovy.json.internal.JsonParserCharArray.complain( at org.apache.groovy.json.internal.JsonParserCharArray.decodeJsonObject( at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal( at org.apache.groovy.json.internal.JsonParserCharArray.decodeJsonArray( at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal( at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue( at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars( at org.apache.groovy.json.internal.JsonParserCharArray.parse( at org.apache.groovy.json.internal.BaseJsonParser.parse( at

Any idea how can I return the ID part of the Json string ?

Thanks for help


1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 06, 2020

HTTPBuilder already takes care of the Json parsing for you since you specified ContentType.JSON. You should not need JsonSlurper here.

But like you said, if the API is giving you a single item, then you can get the id for that item like this:

_userId = json[0].id

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events