1

I have a bash script that returns something like this:

{
  "key1": "value1",
  "key2": "value2"
}

I need to get those values saved as a map in groovy. How do I get that returned value stored as a groovy map?

tim_yates
  • 161,005
  • 26
  • 328
  • 327
DrStrangepork
  • 2,702
  • 1
  • 25
  • 31

2 Answers2

0

You'll want to try something like this:

File script = new File('<My_Script_Path>')
def rawJson = script.getText().execute()
def jsonSlurper = new JsonSlurper()
def result = jsonSlurper.parseText(rawJson)

result should then be structured like your map above.

For more reference, see these links...

Groovy & JSON

This answer showcases running a script

dimwittedanimal
  • 644
  • 1
  • 14
  • 28
0

You should just need

def out = "script.sh".execute().text
def map = new JsonSlurper().parseText(out)
tim_yates
  • 161,005
  • 26
  • 328
  • 327