vaibhavcool20
vaibhavcool20

Reputation: 871

how to get rid of brackets and commas in groovy when printing an array

I need to print an array without parenthesis

part of a json file

 "platforms": [
  {
    "platformCode": "EOS",
    "platformCodeDescription": "Credit Card Servicing  (Voyager) platform"
  },
  {
    "platformCode": "OLB",
    "platformCodeDescription": "Online Retail Bank Servicing Platform"
  }
],

part of code

def list=json.loginModel.get("platforms")
log.info list

output is

[{platformCode=EOS, platformCodeDescription=Credit Card Servicing  (Voyager) platform}, {platformCode=OLB, platformCodeDescription=Online Retail Bank Servicing Platform}]

if I use this code

def list=json.loginModel.get("platforms").platformCode
log.info list

output

[EOS, OLB]

i need the EOS and OLB without "[]"and","

Upvotes: 0

Views: 2387

Answers (3)

vaibhavcool20
vaibhavcool20

Reputation: 871

log.info json.loginModel.get("platforms").platformCode.get(0)
log.info json.loginModel.get("platforms").platformCode.get(1)

will print the desired result

Upvotes: 0

cfrick
cfrick

Reputation: 37008

Join the list of strings

['EOS', 'OLB'].join(" ")
===> EOS OLB

Upvotes: 3

cesar_sr91
cesar_sr91

Reputation: 130

You could create a method like this one and pass your list:

   public String printArray(String[] platfomrs){
        String result = "";
        for(String code:platfomrs)
            result += result + code + " ";

        return result;
    }

Upvotes: 1

Related Questions