I am new to Groovy and i am looking for a way to parse a JSON response from a service that communicates a number of device types it is controlling. There is common and specific information per device that is communicated back. How can i use e.g. JsonSlurper to get this response structured in maps or something similar? An example of the response is below.
{
“ActTime” : 1436785935,
“ServerTime” : “Jul 13 2015 13:12:15”,
“Sunrise” : “05:36:00”,
“Sunset” : “21:56:00”,
“result” : [
{
“BatteryLevel” : 255,
“CustomImage” : 0,
“Data” : “Stopped”,
“Favorite” : 1,
“HardwareID” : 2,
“HardwareName” : “RFXCOM”,
“HaveDimmer” : false,
“HaveGroupCmd” : false,
“HaveTimeout” : false,
“ID” : “000001”,
“Image” : “Light”,
“IsSubDevice” : false,
“LastUpdate” : “2015-07-12 17:44:52”,
“Level” : 0,
“LevelInt” : 0,
“MaxDimLevel” : 0,
“Name” : “Somfy_TV”,
“Notifications” : “false”,
“PlanID” : “0”,
“Protected” : false,
“ShowNotifications” : true,
“SignalLevel” : 7,
“Status” : “Stopped”,
“StrParam1” : “”,
“StrParam2” : “”,
“SubType” : “RFY”,
“SwitchType” : “Blinds”,
“SwitchTypeVal” : 3,
“Timers” : “false”,
“Type” : “RFY”,
“TypeImg” : “blinds”,
“Unit” : 1,
“Used” : 1,
“UsedByCamera” : false,
“XOffset” : “0”,
“YOffset” : “0”,
“idx” : “6”
},
{
“AddjMulti” : 1.0,
“AddjMulti2” : 1.0,
“AddjValue” : 0.0,
“AddjValue2” : 0.0,
“BatteryLevel” : 255,
“CustomImage” : 0,
“Data” : “Off”,
“Favorite” : 1,
“HardwareID” : 2,
“HardwareName” : “RFXCOM”,
“HaveDimmer” : false,
“HaveGroupCmd” : true,
“HaveTimeout” : false,
“ID” : “66”,
“Image” : “Light”,
“IsSubDevice” : false,
“LastUpdate” : “2015-07-12 00:02:33”,
“Level” : 0,
“LevelInt” : 0,
“MaxDimLevel” : 0,
“Name” : “Lamp_Buiten_Achter”,
“Notifications” : “false”,
“PlanID” : “0”,
“Protected” : false,
“ShowNotifications” : true,
“SignalLevel” : 5,
“Status” : “Off”,
“StrParam1” : “”,
“StrParam2” : “”,
“SubType” : “X10”,
“SwitchType” : “On/Off”,
“SwitchTypeVal” : 0,
“Timers” : “false”,
“Type” : “Lighting 1”,
“TypeImg” : “lightbulb”,
“Unit” : 4,
“Used” : 1,
“UsedByCamera” : false,
“XOffset” : “0”,
“YOffset” : “0”,
“idx” : “11”
},
{
“AddjMulti” : 1.0,
“AddjMulti2” : 1.0,
“AddjValue” : 0.0,
“AddjValue2” : 0.0,
“BatteryLevel” : 255,
“CustomImage” : 0,
“Data” : “Off”,
“Favorite” : 1,
“HardwareID” : 2,
“HardwareName” : “RFXCOM”,
“HaveDimmer” : false,
“HaveGroupCmd” : true,
“HaveTimeout” : false,
“ID” : “67”,
“Image” : “Light”,
“IsSubDevice” : false,
“LastUpdate” : “2015-07-12 23:35:27”,
“Level” : 0,
“LevelInt” : 0,
“MaxDimLevel” : 0,
“Name” : “Lamp_Buiten_Hal”,
“Notifications” : “false”,
“PlanID” : “0”,
“Protected” : false,
“ShowNotifications” : true,
“SignalLevel” : 6,
“Status” : “Off”,
“StrParam1” : “”,
“StrParam2” : “”,
“SubType” : “X10”,
“SwitchType” : “On/Off”,
“SwitchTypeVal” : 0,
“Timers” : “false”,
“Type” : “Lighting 1”,
“TypeImg” : “lightbulb”,
“Unit” : 1,
“Used” : 1,
“UsedByCamera” : false,
“XOffset” : “0”,
“YOffset” : “0”,
“idx” : “12”
}
],
“status” : “OK”,
“title” : “Devices”
}
Thanks for your help!