Boninseg Boninseg - 1 year ago 79
JSON Question

Unexpected toke ? in JSON

Good day ,

Trying to make

operations in data table, but getting an
Syntax[Error][1] : Unexpected toke ?
in .json (even though there is no question mark in it) after opening it with fs.readFile.

here is the CRUD part in my NodeJS server : jsfiddle

What part can cause
to be written in .json?

Answer Source

I have worked out the example that you have placed in the JSFiddle link. I found that the issue is with the jsonFileArr = JSON.parse(data); which return to be written as,

jsonFileArr = JSON.stringify(data);
jsonFileArr = JSON.parse(jsonFileArr);

Basically you will have to convert it to a valid JSON string using the stringify before you parse it using the parse function.

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download