LoginSignup
11
7

More than 5 years have passed since last update.

Node.jsにてSyntaxError: Unexpected token in JSON

Posted at

JSONのパースでハマったのでメモ

connpassのAPIから情報取得していて、特定のイベントだけJSONのパースエラーが発生しました。

SyntaxError: Unexpected token < in JSONとかでも
SyntaxError: Unexpected token } in JSONとかでもなく
SyntaxError: Unexpected token in JSONでした。

文字変換などをするときに変な空白が入ることがあって、それが悪さしてしまっている模様。

SyntaxError: Unexpected token in JSON at position 418って感じのエラーだったので

文字カウントサイトでカウントしつつ原因箇所を特定。

確かにタイトルの勉強会の後ろに見えない空白が入ってました。ちなみにtrim()では消えない模様。

空白でよくわからない状態でもposition 418って出るのは優しいかな。。

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7