16

I'm trying to import a large JSON file but I'm getting this error:

Unexpected token , in JSON at position 197031914

how do i go to that position to fix it?

Thanks!

Flip
  • 6,233
  • 7
  • 46
  • 75
tito.300
  • 976
  • 1
  • 9
  • 22

5 Answers5

10

Besides the recommendations of using a json linter, this extension lets you navigate to a specific offset (position) within a file. You'd want to go to offset 197031914.

Keep in mind that if the file has very long lines, VS Code will not display the entire line. You can try adjusting this limit by following these steps

Matt Bierner
  • 58,117
  • 21
  • 175
  • 206
4

Just use a JSON linter. There are plenty online, like this one. The linter will point out the specific errors in the syntax of your JSON file.

Jimmy Leahy
  • 566
  • 3
  • 14
1

I know this is an older question but since its getting some views I want to mention how I ended up solving this issue.

Because I was processing huge files (gigabytes), it was not working with linters, so I ended up solving this issue by writing my script that takes a readable stream and find that position and then return the context (x number of charachters before and after position).

I still use it and I might get around to publish it on npm for others to use. (not sure if someone had already done a similar thing);

tito.300
  • 976
  • 1
  • 9
  • 22
0

Looks like you have a one line file. There is an out-of-the-box command to jump to a line number in VS Code. But there is not for a jump to column. So, simply add this VSCode extension to be able to easily jump to a given column on line.

JLavoie
  • 16,678
  • 8
  • 33
  • 39
  • 1
    it is actually a JSON file where each object in the array is on a new line. I guess when node is importing it, it is first seeing it as a one line string before parsing it. I know that because the error is occurring inside the try block wheere JSON.parse(content) is taking called on the content inside the loader.js module. – tito.300 Mar 20 '19 at 20:41
  • I think node fails when it find the broken JSON string. As I said, install the VS Code extension and check the problematic JSON file. You'll find out right away. You could also just take that first line in the file and paste it in an online linter like this one: https://jsonlint.com/ – JLavoie Mar 20 '19 at 20:56
0

You can auto-fix by linting from the command line using eslint-plugin-json:

$ npm i eslint eslint-plugin-json
$ npx eslint --fix example.json

NOTE: You can get more info about the issue using npx eslint example.json (before fixing).

JBallin
  • 8,481
  • 4
  • 46
  • 51
  • @JLavoie agreed, but comments on other answers suggest that the file is too large to be opened - how do you suggest fixing it manually? I added a way to get more info about the error. Let me know if you have any other suggestions for improvement, thanks! – JBallin Mar 20 '19 at 22:00
  • In this case open the file with vi or vim. vi can open extremely large files. In vi, assuming the error is one row 1, insert mode enter: `:call cursor(1, 197031914)` – JLavoie Mar 21 '19 at 15:20