Last active
May 12, 2019 21:07
-
-
Save nitsanavni/6832542298940e2d1c5be532698a1ae2 to your computer and use it in GitHub Desktop.
groovy String.isJson()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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