How to use the jsonc-parser.stripComments function in jsonc-parser

To help you get started, we’ve selected a few jsonc-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / keymaps / src / common / keymaps-validation.ts View on Github external
export default function parseKeybindings(content: string): Keybinding[] {
    const strippedContent = jsoncparser.stripComments(content);
    const validationError = new ValidationError('Content validation error.');

    // parse the raw content
    const errors: jsoncparser.ParseError[] = [];
    const rawBindings = jsoncparser.parse(strippedContent, errors);
    if (errors.length) {
        for (const error of errors) {
            validationError.messages.push(JSON.stringify(error));
        }
        throw validationError;
    }

    // validate the parsed object
    if (rawBindings) {
        if (keymapsValidator(rawBindings)) {
            return rawBindings;
github eclipse-theia / theia / packages / preferences / src / node / json-preference-server.ts View on Github external
return this.fileSystem.resolveContent(uri).then(({ stat, content }) => {
                    const strippedContent = jsoncparser.stripComments(content);
                    const errors: ParseError[] = [];
                    const preferences = jsoncparser.parse(strippedContent, errors);
                    if (errors.length) {
                        for (const error of errors) {
                            this.logger.error("JSON parsing error", error);
                        }
                    }

                    return preferences;
                });
            }).catch(reason => {
github eclipse-theia / theia / packages / keymaps / src / browser / keymaps-parser.ts View on Github external
parse(content: string, errors?: string[]): Keybinding[] {
        const strippedContent = parser.stripComments(content);
        const parsingErrors: parser.ParseError[] | undefined = errors ? [] : undefined;
        const bindings = parser.parse(strippedContent, parsingErrors);
        if (parsingErrors && errors) {
            for (const error of parsingErrors) {
                errors.push(`${this.printParseErrorCode(error.error)} at ${error.offset} offset of ${error.length} length`);
            }
        }
        if (this.validate(bindings)) {
            return bindings;
        }
        if (errors && this.validate.errors) {
            for (const error of this.validate.errors) {
                errors.push(`${error.message} at ${error.dataPath}`);
            }
        }
        return [];
github igorshubovych / markdownlint-cli / markdownlint.js View on Github external
function jsoncParse(text) {
  return JSON.parse(jsoncParser.stripComments(text));
}
github eclipse-theia / theia / packages / workspace / src / node / default-workspace-server.ts View on Github external
protected async readJsonFromFile(filePath: string): Promise {
        if (await fs.pathExists(filePath)) {
            const rawContent = await fs.readFile(filePath, 'utf-8');
            const strippedContent = jsoncparser.stripComments(rawContent);
            return jsoncparser.parse(strippedContent);
        }
    }