-
• #2
Try
E.toJS
? This is basically JSON5, but I think things like pin names and functions can also be dumped.For parsing, you can just use
eval
- but obviously you need to be able to trust the data since there are security issues there (any JS code in the input will get executed!). -
• #3
first shot
var json = {a:1,b:2}; var data = JSON.stringify(json).replace(/\"/g, ''); // '{a:1,b:2}' var j = E.toJS(data) // "\"{a:1,b:2}\""
Ok, no error but no object - whats missing ?
-
• #4
that .replace won't work with string values like
{a:"Hello",b:2};
as for converting - quick and dirty may be
eval('('+data+')')
-
• #5
Yes, text in json will not be covered ....
ok so let's sum it up
var json = {a:"1",b:2}; data = E.toJS(json); // {a:\"1\",b:2}" j = eval('('+data+')'); // { a: "1", b: 2 }
So, JSON5 is possible on Espruino devices - thanks.
JSON
JSON5
Possible workaround to convert standard JSON to JSON5 for .stringify()
But how to convert a JSON5 data string back to a json object in Espruino?