fifn2
fifn2

Reputation: 382

What JSON validator does VScode use?

I really like the JSON validator that vscode has. It catches errors that a lot of editors don't, so I really want to use it in my pre commit tests. To do that, I was hoping there was an npm equivalent of it.

Let's say I'm linting this JSON file.

{
  "a": "b",
  "b": "c",
  "c": "d",
}

It has a trailing comma, and that's not allowed. However, jsonlint, which appears to be the most popular npm json linter gives the error:

Error: Parse error on line 4:
...b": "c", "c": "d",}
---------------------^
Expecting 'STRING', got '}'

Which could take me forever to track down, whereas vscode:

Trailing comma json(519) [4,11]

That's much easier to read.

Upvotes: 8

Views: 10158

Answers (1)

steve
steve

Reputation: 1856

Trailing commas for JSON was introduced in ES5. Depending on your configuration, you may or may not catch the error above.

You can add a jsconfig.json or tsconfig.json, depending on the language you are using.

{
  "compilerOptions": {
    "target": "es5"
  }
}

Upvotes: 1

Related Questions