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
  • 167,322
  • 27
  • 342
  • 338
DrStrangepork
  • 2,955
  • 2
  • 27
  • 33

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
  • 656
  • 1
  • 13
  • 29
0

You should just need

def out = "script.sh".execute().text
def map = new JsonSlurper().parseText(out)
tim_yates
  • 167,322
  • 27
  • 342
  • 338