In my app, I save a JSON file, and somewhere I load it back.
But when I try to load it back, the parsing process fails:
The saved JSON file as an extra bracket at the end.
Here is a screenshot

So I saved the file in RNFS.DownloadDirectoryPath so I can check it myself from a File Explorer, and yeah, the file on the disk really has an extra bracket. The JSON is invalid.
What's could be the problem? Can someone help?
Versions:
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-fs": "^2.16.6",
Ok, I figured it out.
Workaround: delete the file first.
Here is my actual scenario:
false to trueThe reason is, writeFile() writes over the file, without clearing the content first.
So, if I run
await RNSF.writeFile('lorem.txt', 'hello world !!');
await RNSF.writeFile('lorem.txt', 'hello you');
The file will contain
hello yould !!
^^^^^
From the previous content
Tested and Android.
Thank you!
Still an issue, thanks for the workaround 馃憤
Most helpful comment
馃槷 馃槂
Ok, I figured it out.
Workaround: delete the file first.
Here is my actual scenario:
falsetotrueThe reason is,
writeFile()writes over the file, without clearing the content first.So, if I run
The file will contain
Tested and Android.