How to escape special chars in JSON #1558
Replies: 17 comments
-
Posted at 2021-06-30 by @gfwilliams I'm not sure I understand the issue here? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-06-30 by @MaBecker I try so send JSON5 via nodejs and ble with this sample code https://www.espruino.com/Interfacing and ran into syntax error or eval issues. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-06-30 by @gfwilliams So you're trying to parse the data you received on the PC with If so, if you're using |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-06-30 by @MaBecker Yes, PC sends JSON5 data to nRF device running on Espruino. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-01 by @gfwilliams Sorry, I'm not sure I understand...
So it's Espruino that has trouble decoding the data from the PC? Or the PC that has trouble decoding data from Espruino? Because if you're using |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-02 by @MaBecker
Sample code on Mac that is causing no issues when sending to a Espruino device after two time
sample code on PuckJS
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-02 by @MaBecker Sample code on PuckJS that is causing issues if not escaped when sending to a Espruino device after two times
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-02 by @gfwilliams I just tried:
in the emulator So I don't really see what the problem is here? I guess there is maybe some problem with how you are sending this? It seems to me from your replace of |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-02 by @MaBecker
Wow - many thanks code on Puck:
I tried this:
removing the extra " and it works fine
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-04 by @MaBecker Ok, let's look at JSON.
Hope you have an idea why the extra escaping is needed? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-05 by @gfwilliams
Both of those are adding extra quotes, just in different ways? What about:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-05 by @MaBecker
yes and both only work when sending
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-06 by @gfwilliams I don't understand. I ran this on a Pixl, talking to a Puck.js, and it works great using
Reports:
Using Is your
If so then the issue is that in So...
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-06 by @MaBecker Wow, just copied the code from your response and it works - I guess this has to do with code pages differences. I write code with a Mac OS editor and load the file into thee WebIDE.
Maybe some quotes got effected as well ..... Many thanks, using replace was just a workaround and I am happy to remove them again. Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-06 by @MaBecker Ok, so if
Reports:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-07 by @gfwilliams
Nope... because cmd is So what you're doing is telling Espruino to do : The JSON is already parsed by the command-line. There's no need to parse it at all - what you get is the actual JSON object you wanted in the first place! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-07-07 by @MaBecker
Thanks for your support and clarification! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-06-30 by @MaBecker
Got some special chars in JSON that needed to be escapes.
Is there a Espruino function for this, or could this be another candidate for
StringDecoders
?Beta Was this translation helpful? Give feedback.
All reactions