0

I have a dictionary that I get as a python dictionary in groovy which I then assign to a variable x :

def x = "{'JIRACHEF': 'PIBEP-2135', 'JIRADEPLOYER': 'PIBEP-2136', 'JIRASINGLEBUILD': 'PIBEP-2137'}"

I want to parse the above and get values for :

  • JIRACHEF
  • JIRADEPLOYER
  • JIRASINGLEBUILD

whats the most elegant groovy way of doing it ?

2
  • 1
    What exactly do you need? Assign variables values? Commented Jan 16, 2017 at 15:56
  • @sisanared - how to go about doing that ? Commented Jan 16, 2017 at 16:02

1 Answer 1

2

You can use the LAX slurper (in recent versions of Groovy):

import groovy.json.*

def x = "{'JIRACHEF': 'PIBEP-2135', 'JIRADEPLOYER': 'PIBEP-2136', 'JIRASINGLEBUILD': 'PIBEP-2137'}"

def parsed = new JsonSlurper().setType(JsonParserType.LAX).parseText(x)

println parsed.JIRACHEF
println parsed.JIRADEPLOYER
println parsed.JIRASINGLEBUILD
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.