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



Solution 1:[1]

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"
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 steve