Skip to content

Instantly share code, notes, and snippets.

@nitsanavni
Last active May 12, 2019 21:07
Show Gist options
  • Save nitsanavni/6832542298940e2d1c5be532698a1ae2 to your computer and use it in GitHub Desktop.
Save nitsanavni/6832542298940e2d1c5be532698a1ae2 to your computer and use it in GitHub Desktop.
groovy String.isJson()
String.metaClass.isJson << { ->
def normalize = { it.replaceAll("\\s", "") }
try {
normalize(delegate) == normalize(JsonOutput.toJson(new JsonSlurper().parseText(delegate)))
} catch (e) {
false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment