Changing Thingspeak JSON string data to JSON decimal data

andy neo on 9 Jun 2021
Latest activity Reply by Christopher Stapels on 31 Aug 2022

Hi,

I managed to get Thingspeak JSON data from my channel. However, I would like to know if theres any way to convert Thingspeak's JSON string data to decimal. I would really appreciate it if anyone could tell me how to convert it to decimal.

Currently, this is my JSON: { "created_at": "2020-10-08T09:24:00.0000000Z", "entry_id": 1, "field1": "0", "field2": "12", "field3": "1", "field4": "1", "field5": "1", "field6": "1" }

May I know if it is as simple as deleting the ""? For eg,

{ "created_at": "2020-10-08T09:24:00.0000000Z", "entry_id": 1, "field1": 0, "field2": 12, "field3": 1, "field4": 1, "field5": 1, "field6": 1 }

Christopher Stapels
Christopher Stapels on 9 Jun 2021

Are you reading the JSON data with a device, or with MATLAB, or with some other code? MATLAB can definitely convert the JSON for you. On a device, you might consider using a JSON library, or reading a single field. When you read a single field, the number is returned as test, which might be easier for you to convert.

andy neo
andy neo on 9 Jun 2021

Hi. I am sending sensor data from my hardware to Thingspeak. After getting the values in Thingspeak, I then write "https://api.thingspeak.com/channels/ChannelNumber/feeds/1.json" to get the JSON data in Thingspeak.

The resulting result is: { "created_at": "2020-10-08T09:24:00.0000000Z", "entry_id": 1, "field1": "0", "field2": "12", "field3": "1", "field4": "1", "field5": "1", "field6": "1" }

Hence, I was wondering if it is possible to change the strings for all of the fields to either decimal or integer.

I sincerely apologize if I am asking a simple question but I just cant seem to figure out other than deleting the "", as the result of entry_id is an integer not a string.

Jay Wan
Jay Wan on 31 Aug 2022
Hello
I am facing the same problem. Sent data was 4.94, read data was 4.00. No idea why???
Sent data was 4.94
{"created_at":"2022-08-28T23:38:23-04:00","entry_id":1269,"field4":"4.94"}]}
Read data was 4.00
Code:
long PHTS = ThingSpeak.readLongField(counterChannelNumber, FieldNumber4, myCounterReadAPIKey);
int statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("ThingSpeak pH: ");
Serial.println(PHTS);
}
How to display 4.94 (actual data) when reading the data.
Thanks
Christopher Stapels
Christopher Stapels on 31 Aug 2022
ThingSpeak.readFloatField