Agent is escaping caracters between agent and device badly

I have a JSON that containt a key with a value of °F , and when the device receive the JSON, °F is converted to \u00b0F

Problem is, whatever i’m trying to do with this variable in the device, I’ve got the message Syntax error (line xxx): unrecognised escaper char

Its kind of strange since now I have to escape the degrees sign myself in the agent both ways ( agent to device and device to agent) so the transmission between those will not corrupt my message

Any way around that?

This is because the degree symbol is not ASCII and hence it’s UTF-8 encoded (it’s not a single byte in the string).

I suspect you’re doing something which is assuming that it is a single byte? If you can include your code, we can probably help.

The mbstring library may help, depending on what you’re trying to do: https://electricimp.com/docs/libraries/utilities/mbstring/

Well, i’m sending a Json with a key that have the value of “°F” and when the device get it, it is no longer °F i’ve solved my problem, I do remove the degree symbol in the agent before sending it, and I re-add it on the device, its ugly code but its fine

Would be nice to know what you were doing that threw that error; I just checked and had no issues sending a table with a key that was that value:

agent:
imp.wakeup(1, function() { device.send("degree", {"°F": 32}); });

device:
agent.on("degree", function(v) { foreach(a,b in v) { server.log(a); server.log(b); } });

…as expected it logs:

2016-06-18 19:53:59 UTC-7 [Device] °F 2016-06-18 19:53:59 UTC-7 [Device] 32

In my experience, device-to-agent and agent-to-device transfers do not perfectly reproduce your data. Blobs are down-converted into strings but are not converted back afterwards. Squirrel allows you to use integers as keys for tables, but they also get converted to strings when passed between agent and device. To avoid all of this (and the problem that you are having), I only use safe strings for keys.