Ansh Malik
Ansh Malik

Reputation: 392

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

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

Upvotes: -2

Views: 418

Answers (1)

ranjanistic
ranjanistic

Reputation: 151

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)

Upvotes: 0

Related Questions