Hi,
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.name); println(object.ID); } }
but the result is "class Example" not name and ID.
Is there any workaround for this? Thanks.
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
object.name
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ramondrio Imanuel ,
I apologize, but I don't understand. Would you please provide me more information, what you are trying to achieve?
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.