I'm having the following JSON object which I want to check
import groovy.json.JsonSlurper
def jsonSlurper = new JsonSlurper()
import groovy.json.JsonOutput;
def object = jsonSlurper.parseText '''
{
"id" : 10,
"docType" : "PDF",
"values" : {
"color" : "red",
"pages" : 2,
},
"versions" : [
{
"verNum" : 1,
"desc" : "This is the description for it"
}
]
}
'''
// def data = new JsonSlurper().parseText("""[{"a": 1, "b": 2, "c": 3, "x": true}, {"a": 4, "b": 5, "c": 6, "d": "Hello"}]""")
// def content = object.collectEntries{
// it.collectEntries{
// [it.key, it.value.class.name]
// }
//}
//println content
I want to iterate through each of the keys and check for the type using Groovy, for example: id - java.lang.Integer, docType - java.lang.String, values.color - java.lang.String, verNum within the object within the array will be java.lang.Integer
I have searched for a few different ways but most of them won't work in my case. One of them are now commented on as in the code above.
Any suggestion would be much appreciated!