groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Antonelli <>
Subject Re: Groovy script to replace Json values via a mapping file
Date Tue, 07 Jun 2016 23:50:01 GMT
Hi Ilaria,

did not quite understand what you are trying to do but for sure you are
messing up passing the slurper to the builder. As far as I understood you
want to replace values or delete them (A2?) from a json so better work on

def json = '''

def mapping = '''
def slurper = new JsonSlurper().parseText(json)
def conf = new ConfigSlurper().parse(mapping)

def map = slurper.collectEntries { k, v ->
    if (k == 'field2' && conf[v]) v = conf[v]
    if (k == 'field3' && conf[v]) return [:] // what do you mean with
"if field3 has value if A then substitute to A2" ??
    [(k): v]

new JsonBuilder(map).toPrettyString()

note the mapping format is different from the one you have. I don't think
the conifgslurper can be configured to understand yours.
For questions like this you should you stackoverflow, you may find more
people willing to help you.


On Tue, 7 Jun 2016 at 23:15 idioma <> wrote:

> Hi,
> I was hoping to get some feedback from this community on how my attempt can
> be improved in any way or whether I am actually heading towards the wrong
> direction.
> Thank you so much,
> I.
> --
> View this message in context:
> Sent from the Groovy Users mailing list archive at

View raw message