Unexpected token � in JSON at position 0, when reading and parsing JSON from output file

308 Views Asked by At

I am trying to read a json file produced by a powershell script which reads another powershell script and outputs an Abstract Syntax Tree of the that script to a json file When I try to read this output json file and parse it as json using nodejs I get the following error (although the json file looks like valid json when i open it in vscode )

undefined:1
��[
^
Unexpected token � in JSON at position 0
1

There are 1 best solutions below

0
ranjanistic On

The error is indicating some unsupported characters at the beginning of your json ��

��[
^
Unexpected ...

That is most likely the reason for this error, as it seems. There could also be other kind of problems like

  • invalid json syntax (check for quotations, trailing commas, etc.)
  • Json file content not being sent properly to the parser (ensure that you're passing the proper json content, without any kind of noise like the one shown in your error)