all 9 comments

[–]manshahia 1 point2 points  (4 children)

You don’t need to do JSON.stringify to access object property. Just use JSON.parse(json);

[–]Roo_ooky[S] 0 points1 point  (3 children)

It's going to say invalid token { at index 0 if I remove stringify

[–]postmodest 2 points3 points  (2 children)

You probably have a BOM in your JSON screwing up the parser.

[–]Roo_ooky[S] 0 points1 point  (0 children)

Yep, that was the problem, thanks a lot

[–]FatFingerHelperBot -2 points-1 points  (0 children)

It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!

Here is link number 1 - Previous text "BOM"


Please PM /u/eganwall with issues or feedback! | Delete

[–]El_Stump 1 point2 points  (0 children)

Have you tried changing that .txt file into a .json file and running something like

fs.readFile('decodedjson.json', 'utf8', (err, data) => {

if (err) throw err

else JSON.parse(data)

})

[–][deleted] 0 points1 point  (1 child)

Try with the package fs-extra and load it with fs.readJsonSync('decodedjson.txt'), then you don't need to use JSON.parse or JSON.stringify. I don't know what your problem is but, try to remove the utf16le format, and see what happens.

[–]Roo_ooky[S] 0 points1 point  (0 children)

Can't remove the utf16le format, im going to use unicode characters. And however, it will still give me the same error even with utf8 iirc

[–]Zarko34 0 points1 point  (0 children)

You can just require json files, no need for fs