Getting an Error Using Library: JSON Parser Tool

Using an IMP003, I am trying to use the JSON parser tool library but get the following error. “This might be a rookie mistake I am new to JSON”.

2016-06-19 00:35:27 UTC-4 [Agent] ERROR: the index 'slice' does not exist 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: in parse ...imp#jsonparser.class.nut#1.0.0:285 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: from getUbiDotsPwrBtn agent_code:505 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: from main agent_code:823

This is the code I am using inside a function:
`#require "JSONParser.class.nut:1.0.0"
function getUbiDotsPwrBtn(){
local headers = { “Content-Type”: “GET”, “X-Auth-Token”: UBIDOTS_X_Auth_Token }; // Replace the token with yours

local url = “http://things.ubidots.com/api/v1.6/variables/<>/values/?page_size=1&token=<>”;
server.log(url);
local request = http.get(url, headers);
local response = request.sendsync();
result = JSONParser.parse(response);
server.log(result.count);
}`

The response being received is the following:
{ "count": 11, "next": "http://things.ubidots.com/api/v1.6/variables/57562c06762542450a5e5000/values/?token=i35cpIjr1KeRQvA4PC2zAIRwWfUENG&page=2&page_size=1", "previous": null, "results": [ { "url": "http://things.ubidots.com/api/v1.6/values/53861ce276254261831076bb", "value": 1.0, "timestamp": 1466309858069, "context": {}, "created_at": "2016-06-19T04:17:38.069" } ] }

See https://electricimp.com/docs/api/httprequest/sendsync/

request.sendsync() returns a table { statuscode, headers, body }. You need to check what’s in the table first (ie did the request complete successfully), then decode the JSON, which will be in response.body.

Generally, if you are decoding JSON in the agent, you don’t need the library, you can just use http.jsondecode(response.body)

PS. It’s always a good idea to wrap json decoding in try/catch as it will throw an exception if it has any trouble deciphering it.