Groovy web console

subscribe to the feed Subscribe
to this
site
Compare map keys (via #groovywebconsole)
tweet this snippet Tweet
this
script

Compare map keys

Published 2 weeks ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import groovy.json.*

def json1 = '{"value": "123", "field" : "xyz"}'
def json2 = '{"name" : "efg", "value": "567", "field" : "xyz"}'

def slurp1 = new JsonSlurper().parseText(json1)
def slurp2 = new JsonSlurper().parseText(json2)
assert slurp1.keySet() == slurp2.keySet()