• Hello,

    I recently upgraded my Bangle1 to 2v20 and discovered that the writeJSON optimization that skips quotes on alphanumeric field names broke my apps. My use case is probably uncommon but I thought I'd mention the workaround I came up with just in case it ever helps anybody else.

    Basically, I gather data on my Bangle and save it to JSON formatted files. Using the IDE I export the files to my computer, then import them back into the Bangle emulator. I then run different Bangle apps in the emulator to graph the data (and take screenshots of the graphs).

    Anyway, starting with 2v20, writeJSON skips the quotes on alphanumeric field names and because of this, when I used readJSON in the emulator to load the files imported from my Bangle I got a syntax error complaining about the missing quotes. I guess it would be nice for there to be an option added to writeJSON to still include the quotes but until then a simple workaround is just to use write("filename", JSON.stringify("json value")) in lieu of writeJSON("filename", "json value").

    I've uploaded a sample script to replicate the problem with my workaround commented out.

    As always, many thanks to Gordon and the Espruino team for all their amazing and wonderful work!

    1 Attachment

  • Not sure what the problem is, when I try the attached script on 2v20.27 I get

    "key1": "value"

    no error.

  • Also you might want to check issues#3110 and try the new Util.readStorageJSON() (or replicate what it does after downloading the files from the IDE)

  • So I think the issue you have is just that the Emulator was out of date, so wouldn't load those files?

    As mentioned if you're using the app loader to load then it can automatically parse the new format.

    I've just updated the emulator, so that should be fixed for you now too

  • Oh--I hadn't noticed that the emulator was out of date, thank you @Gordon for updating it and resolving my issue! And thank you @user140377 for advising me about Util.readStorageJSON().

  • @Gordon Could we also currently have an issue with backup/restore? I just tried a backup from one Watch and restore on the other and the json files can no longer be read, e.g. sched:

    Uncaught SyntaxError: Got ID:t expected '}'
    at line 1 col 3 in sched.json

  • Is the watch you restored onto running up to date firmware? If the firmware was older than 2v20 then you'd have an issue

    I didn't think it should be a problem as the files for backup should be read/written in binary.

  • Sorry my fault, I thought I updated. Firmware .20 works.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

2v20 writeJSON optimization broke my app [Workaround]

Posted by Avatar for TTBangler @TTBangler