'How vscode parses json files that are used for extension configurations?

How VSCode parses json files like language-configuration.json that is used to describe language extensions? I see that these files contain comments and many, like typescript, contain trailing commans.

If such content is parsed using JSON.parse() the error will be raised.

I implement an extension that reads these config files and like to use the same parsing method that is used in vscode.

Thank you



Solution 1:[1]

I would assume they use the jsonc-parser - since it is written by one of the vscode team and has 3 million+ downloads a week.

npm package: jsonc-parser

I use it myself because I need to parse complicated custom settings that might have comments in them for example.

Add the package to your dependencies. npm install --save jsonc-parser

Then import it (I have it in a js extension for now):

const jsonc = require("jsonc-parser");

const rootNode = jsonc.parseTree(document.getText());

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 Mark