Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Convert JSON to Groovy


I want to convert JSON Header into Groovy Script. I already try to write this script in my scriptrunner console :

import groovy.json.JsonSlurper 
class Example { static void main(String[] args) { 
def jsonSlurper = new JsonSlurper() 
def object = jsonSlurper.parseText('{ "name": "John", "ID" : "1"}') 
println(object.ID); } 

 but the result is "class Example" not name and ID.


Is there any workaround for this? Thanks. 

1 answer

Hi @Ramondrio Imanuel ,

try to add "as Map" like this:

import groovy.json.JsonSlurper

String requestBody = '{ "name": "John", "ID" : "1"}'

JsonSlurper jsonSlurper = new JsonSlurper()
Map object = jsonSlurper.parseText(requestBody) as Map


Hi @Hana Kučerová ,

Thanks. it works. I also want to define json headers parameters in groovy script. Is there any workaround for that? Thanks.

Hana Kučerová Community Leader Apr 08, 2021

Hi @Ramondrio Imanuel ,

I apologize, but I don't understand. Would you please provide me more information, what you are trying to achieve?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

JSM Jira Automation: How to Send SLA Breached Notifications

Hi Everyone, In   this tutorial,  we will show you how you can monitor an SLA, and send notifications before or after the SLA has been breached.   SLA Threshold Trigger The SLA t...

688 views 5 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you