Issue with writing and reading JSON files



Bryce Beattie

I'm trying to use HTML compiler to save and load .json flavored text files. If I use javascript's JSON.stringify and JSON.parse I can encode and decode data fine. However, when I use stringify to get a string and write it to a file, then read it in to a string and use parse, Javascript throws an "unknown character" error.

For what it is worth, I opened the file written by appReadFile and copy and pasted the stringify results into a json validator, and it says the text is valid json.

If I have javascript write out those two strings (the one i write to the file and the one i read from the file, they strings look the same, but javascript says they are not === or ==.

Is it possible that appReadFile is inserting a hidden character somewhere?


David Esperalta

Hello Bryce,

Certainly write and read operations don't add nothing to the file to be write or read. Look at the below "index.html" sample, I try it and works as expected after apply the "trim" function, so, probably you need to apply that "trim" function too?


Consider to purchase one or more licenses of our products: press here!

Bryce Beattie
That did it. I'm not sure why JSON.parse can't deal with an extra whitespace character, but it's now working. Thanks!

David Esperalta

Hello Bryce,

You're welcome! Certainly, I remember the "space" issue in other environments, languages, etc... I am not completely sure where, but, when you post here the issue, what I first before anything else is to trim the JSON... just because remember that I get the same issue in the past, not related with HTML Compiler!


Consider to purchase one or more licenses of our products: press here!

Everybody can read the DecSoft's support forum for learning purposes, however only DecSoft's customers can post new threads. Purchase one or more licenses of some DecSoft's products in order to give this and other benefits.