I’m trying to parse out the following json string:
{"cid":"PWER","data":[{"1440023704000":0}],"sid":"123456","units":"kWm","age":142156},{"cid":"PWER_GAC","data":[{"1440165858000":2202}],"sid":"123456","units":null,"age":2}
Here is the code snip i’m using:
def respData = summaryResp.data.text
log.debug "Summary Reading Result: $summaryResp.data"
log.debug "Summary text: ${respData}"
def list = new JsonSlurper().parseText(respData)
def cids = list.cid
log.debug "Cid List: $cids"
log.debug "List Values: $list"
if(list.cid == "PWER_GAC" && list.age <= 10)
clampType = "PWER_GAC"
log.debug "PWER_GAC Data ${list.data}"
log.debug "PWER_GAC TimeStamp: ${list.data}"
log.debug "PWER_GAC Reading: ${list.data}"
if(list.cid == "PWER" && list.age <= 10)
clampType = "PWER"
log.debug "PWER Data ${list.data}"
log.debug "PWER TimeStamp: ${list.data}"
log.debug "PWER Reading: ${list.data}"
I need to find the cid value where the age is less than 10 seconds. Then split the value of the data
"data":[{"1440165858000":2202}]
field into two strings (First is timestamp and second is the energy reading)
Here is the Logs…
debug PWER Reading: [[1440181448000:1428]]
debug PWER TimeStamp: [[1440023704000:0]]
debug PWER Data [[[1440023704000:0]], [[1440181448000:1428]]]
debug PWER_GAC Reading: [[1440181448000:1428]]
debug PWER_GAC TimeStamp: [[1440023704000:0]]
debug PWER_GAC Data [[[1440023704000:0]], [[1440181448000:1428]]]
debug List Values: [[sid:123456, age:157749, data:[[1440023704000:0]], cid:PWER, units:kWm], [sid:123456, age:5, data:[[1440181448000:1428]], cid:PWER_GAC, units:null]]
debug Cid List: [PWER, PWER_GAC]
debug Summary text: [{"cid":"PWER","data":[{"1440023704000":0}],"sid":"123456","units":"kWm","age":157749},{"cid":"PWER_GAC","data":[{"1440181448000":1428}],"sid":"123456","units":null,"age":5}]