{"id":14653,"library":"jsonc-simple-parser","title":"JSONC Simple Parser","description":"jsonc-simple-parser is a lightweight and performant JavaScript/TypeScript library designed to parse JSON-like data that includes comments (JSONC) and optional trailing commas. Currently stable at version 3.0.0, this package stands out for its minimal bundle size, being approximately 3.5kb minified and gzipped (or ~2kb if `RegHex` is already in your bundle). It boasts exceptional performance, often being 10x faster than VS Code's `jsonc-parser` and 70x faster than `JSON5` for standard JSON, and equally fast for JSONC. The library prioritizes correctness by passing all 274 JSON tests from ECMA's test262 suite, ensuring reliable parsing despite its non-spec-compliant nature (as standard JSON does not allow comments or trailing commas). It ships with built-in TypeScript types for an enhanced developer experience.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/fabiospampinato/jsonc-simple-parser","tags":["javascript","jsonc","json","comments","trailing commas","commas","parser","parse","stringify","typescript"],"install":[{"cmd":"npm install jsonc-simple-parser","lang":"bash","label":"npm"},{"cmd":"yarn add jsonc-simple-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsonc-simple-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary API is exposed as a default export, primarily designed for ESM. Direct CommonJS `require` might lead to accessing `.default`.","wrong":"const JSONC = require('jsonc-simple-parser');","symbol":"JSONC","correct":"import JSONC from 'jsonc-simple-parser';"},{"note":"The `parse` function is a method of the default `JSONC` export, not a named export itself.","wrong":"import { parse } from 'jsonc-simple-parser';","symbol":"parse","correct":"import JSONC from 'jsonc-simple-parser';\nconst parsed = JSONC.parse(source);"},{"note":"Like `parse`, `stringify` is a method of the default `JSONC` export. It behaves identically to `JSON.stringify`.","wrong":"import { stringify } from 'jsonc-simple-parser';","symbol":"stringify","correct":"import JSONC from 'jsonc-simple-parser';\nconst str = JSONC.stringify(data);"}],"quickstart":{"code":"import JSONC from 'jsonc-simple-parser';\n\nconst source = `\n  { // This is an example comment\n    \"name\": \"Alice\",\n    \"age\": 30,\n    /* This is another comment */\n    \"tags\": [\"developer\", \"js\", \"ts\",],\n  }\n`;\n\n// Parse the JSONC string into a JavaScript object\nconst parsedObject = JSONC.parse(source);\n\nconsole.log('Parsed Object:', parsedObject);\n/* Expected output:\n{\n  name: 'Alice',\n  age: 30,\n  tags: [ 'developer', 'js', 'ts' ]\n}\n*/\n\n// Stringify a JavaScript object back to a JSON string (comments will be lost)\nconst dataToSave = { userId: 123, settings: { theme: 'dark' } };\nconst jsonString = JSONC.stringify(dataToSave, null, 2);\n\nconsole.log('Stringified JSON:', jsonString);","lang":"typescript","description":"Demonstrates parsing a JSONC string containing comments and trailing commas, and then stringifying a plain object back to standard JSON."},"warnings":[{"fix":"Review the official changelog or release notes for `jsonc-simple-parser` v3.0.0 on its GitHub repository to understand any API changes or behavioral modifications and update your code accordingly.","message":"Major version 3.0.0 was released, which typically indicates breaking changes. While the README does not explicitly list them, users should consult the package's GitHub releases or changelog for specific migration details.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If you need to preserve comments or trailing commas, `jsonc-simple-parser` does not provide this functionality on stringification. Consider alternative approaches or other libraries if comment preservation is a requirement for output.","message":"The `JSONC.stringify()` method behaves identically to the native `JSON.stringify()`. This means that any comments or trailing commas that were present in the original JSONC string will be removed during the stringification process.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware that output generated by `JSONC.stringify` (which is standard JSON) will lose these non-standard features. Ensure downstream systems expecting strict JSON will not encounter issues if you manually re-introduce comments for human readability.","message":"While `jsonc-simple-parser` correctly parses JSON with comments and trailing commas, it is not strictly compliant with the ECMA-404 JSON specification, as the native JSON spec does not allow these features. This is by design, as it implements the 'JSONC' (JSON with Comments) standard.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Replace `JSON.parse(jsoncString)` with `JSONC.parse(jsoncString)`.","cause":"Attempting to parse a JSONC string (with comments) using the native `JSON.parse()` instead of `JSONC.parse()`.","error":"SyntaxError: Unexpected token / in JSON at position X"},{"fix":"Ensure you are using `import JSONC from 'jsonc-simple-parser';` for ESM, or if in CommonJS, try `const JSONC = require('jsonc-simple-parser').default;` (though ESM `import` is recommended).","cause":"Incorrectly importing or accessing the `parse` method, often when trying to use CommonJS `require` with an ESM-first default export without accessing the `.default` property.","error":"TypeError: Cannot read properties of undefined (reading 'parse')"},{"fix":"Run `npm install jsonc-simple-parser` or `yarn add jsonc-simple-parser`. Ensure your `tsconfig.json` has `moduleResolution` set appropriately (e.g., `bundler` or `node16`) and that the module is correctly referenced in your import statements.","cause":"The package is not installed, or TypeScript is unable to resolve the module path or its type definitions.","error":"TS2307: Cannot find module 'jsonc-simple-parser' or its corresponding type declarations."}],"ecosystem":"npm"}