Converting JSON String to Number

#1

I’m sending data as a string (I can’t change this), but it’s really a number.
"body": { "event": "structure_blank_A0", "data": "930" }

I have the Virtual Device attribute set as a Number (not a string) and I see that it is converting it as far as I can tell:
{ "data": 930 }
^This is from the device window.

But when I attempt to plot it on my dashboard as a time series graph, it’s stuck at zero. I’m getting the correct data in the Gauge block, so I know it’s receiving my data.

Is there a way to convert the data in my workflow? Or a bug or some other issue that isn’t letting me plot the data? Thanks!

0 Likes

#2

Hey Dillon, what’s your dashboard ID that has the time series graph? It’ll be in your URL /dashboards/:id. Dashboard IDs aren’t sensitive, so don’t worry about pasting it in here.

0 Likes

#3

https://app.getstructure.io/#/dashboards/56ccd42b46e56a0100b5c66c

0 Likes

#4

All the data is being stored correctly as numbers. We’re digging in to find underlying cause of the graph issue.

0 Likes

#5

Found the underlying cause. It was due to the data type of the attribute being changed from string to number. We are releasing a fix shortly. In the meantime, a workaround is to remove the reading attribute, add an attribute of a different name, and switch the implementation to use the new attribute. Sorry for the inconvenience!

0 Likes

#6

On a related note, Structure does attempt to automatically cast the incoming data to the type specified on the attribute. So if you use an attribute of type Number and report a string, it will be cast to a number automatically.

0 Likes

#7

The fix has been pushed, and it now looks like your graph is working. Sorry again!

1 Like

#8

No problem. Thanks for checking it out!

0 Likes