Elmo Tabuzo:
This question already has an answer here:
- Does Groovy have method to merge 2 maps? 1 answer
I would like to know how to replace the string inside JSON to another JSON.
def old = '{"name" : "abc", "value": "123", "field" : "xyz"}'
def neww = '{"name" : "abc", "value": "345" ,"field" : "xyz"}'
def old_1 = new JsonSlurper().parseText(old)
def neww_1 = new JsonSlurper().parseText(neww)
def commons_slurp = old_1.intersect(neww_1)
def difference_slurp = old_1.plus(neww_1)
def final_slurp = difference_slurp.minus(commons_slurp)
def replace_slurp = old.replace(final_slurp)
print '\n' + replace_slurp
and the final output is {"name" : "abc", "345": "123", "field" : "xyz"}
I want the to replace the old value with the new value.
AND, i need that the output would be {"name" : "abc", "value": "345", "field" : "xyz"}
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE