Hello before marking this as duplicate please note that i did tried this and this solution and they both did not worked for me. I am starting a child process in Node.JS and process starts a python file the python script at the end dumps the dictionary list into JSON which is valid as i parsed that json in this website. The main problem is that the collected json is not being parsed in Node.JS it shows the following error
SyntaxError: Unexpected token / in JSON at position 0
The code fragment is following
let output = '';
model = spawn("python3", ["./scanners/python/scan.py", code]);
model.stdout.on("data", function (data)
{
output += data.toString();
console.log(data.toString());
});
model.stderr.on("data", function (data)
{
output += data.toString();
console.log(data.toString());
});
model.on("close", function (exitCode)
{
let result = JSON.parse(output.trim()); //exception is here
}
I tried the following methods to get rid of this but with no luck.
- Trimmed the output e.g. output.trim()
- Removed invisible control characters code taken from here
- Removed other trailing or leading characters code taken from here
- Tried with substring to not consider first character at position 0 then error changes e.g. invalid token v at position 0
kindly help, it is very frustrating