简体   繁体   中英

Replaceall JSON in Groovy for Jenkins

hoping you all ok and your family as well, i need to ask something kinda noob. I'm working right now with Groovy for some proyect in jenkins. My json file has a lot names: "Ingress_1", "Ingress_2" and so on, so i'll try with the famous replaceAll but nothing happens:

Here's the code:

import groovy.json.JsonSlurper
if(the_suite.equals("Asset_important"))
{
def process =["cat",".blabla/jsonfile.json"].execute()
def jsonSlurper = new JsonSlurper()
List<String> artifacts = new ArrayList<String>()
def object_a = jsonSlurper.parseText(process.text)
def object = object_a.replaceAll(/_/, ' ')

assert object instanceof Map
for(i=0;i<object.data.size();i++){        artifacts.add(object.data[i].feature)
 }

I already tried with replaceAll("/_/", ' ')

Thanks for read this:)

replaceAll() is only defined for String , but you are trying to use it on the result of JsonSlurper.parseText() , which is of type Object .

This should work:

def object = jsonSlurper.parseText(process.text.replaceAll('_', ' '))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM