tito.300
tito.300

Reputation: 1146

How to search for a specific position in a JSON file?

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!

Upvotes: 18

Views: 31098

Answers (5)

tito.300
tito.300

Reputation: 1146

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);

Upvotes: 1

Matt Bierner
Matt Bierner

Reputation: 65543

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

Upvotes: 12

JBallin
JBallin

Reputation: 9807

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).

Upvotes: 0

JLavoie
JLavoie

Reputation: 17616

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.

Upvotes: 0

Jimmy Leahy
Jimmy Leahy

Reputation: 666

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.

Upvotes: 4

Related Questions