{"id":14134,"library":"tiny-jsonc","title":"Tiny JSONC Parser","description":"tiny-jsonc is an extremely lightweight JavaScript and TypeScript library designed specifically for parsing JSONC (JSON with Comments) strings. Currently at version 1.0.2, it employs a minimal, regex-based approach to first strip comments and then trailing commas from a JSONC input string. The cleaned string is then passed directly to the native `JSON.parse` function for final object instantiation. This method prioritizes small bundle size and operational simplicity, making it particularly suitable for environments where minimizing dependencies and code footprint is critical. It does not offer advanced JSONC manipulation APIs, rich error messages, or comprehensive parsing features found in full-blown parsers. The library's stable nature and focused scope suggest a maintenance-oriented release cadence, emphasizing reliability over rapid feature development. Developers needing more robust error handling or advanced parsing capabilities are explicitly directed to alternatives like `jsonc-simple-parser`.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/fabiospampinato/tiny-jsonc","tags":["javascript","jsonc","json","comments","trailing commas","commas","parser","parse","typescript"],"install":[{"cmd":"npm install tiny-jsonc","lang":"bash","label":"npm"},{"cmd":"yarn add tiny-jsonc","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiny-jsonc","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library's main functionality is exposed as a default export named `JSONC`, which contains the `parse` method. It is primarily designed for ES Module environments and ships with TypeScript types.","wrong":"import { JSONC } from 'tiny-jsonc';","symbol":"JSONC","correct":"import JSONC from 'tiny-jsonc';"},{"note":"While CommonJS `require` might work with module interop, the library's documentation and intended usage patterns favor ES module `import` statements.","wrong":"const JSONC = require('tiny-jsonc');\nconst parsed = JSONC.parse(source);","symbol":"JSONC.parse","correct":"import JSONC from 'tiny-jsonc';\nconst parsed = JSONC.parse(source);"}],"quickstart":{"code":"import JSONC from 'tiny-jsonc';\n\nconst sourceWithCommentsAndTrailingCommas = `\n  { // This is an example comment\n    \"productName\": \"Example Widget\",\n    \"price\": 123.45,\n    /* This is a multi-line comment */\n    \"features\": [\n      \"featureA\",\n      \"featureB\", // Inline comment\n      \"featureC\",\n    ],\n    \"metadata\": {\n      \"id\": \"abc-123\",\n      \"timestamp\": 1678886400000,\n    }, // Trailing comma on object property\n  }\n`;\n\ntry {\n  const parsedObject = JSONC.parse(sourceWithCommentsAndTrailingCommas);\n  console.log('Successfully parsed JSONC:');\n  console.log(JSON.stringify(parsedObject, null, 2));\n  // Expected output will be valid JSON without comments and trailing commas\n  // e.g., { \"productName\": \"Example Widget\", \"price\": 123.45, \"features\": [ \"featureA\", \"featureB\", \"featureC\" ], \"metadata\": { \"id\": \"abc-123\", \"timestamp\": 1678886400000 } }\n} catch (error) {\n  console.error('Failed to parse JSONC:', error.message);\n}","lang":"typescript","description":"This quickstart demonstrates how to import and use `tiny-jsonc` to parse a JSONC string containing both single-line and multi-line comments, as well as trailing commas, into a standard JavaScript object."},"warnings":[{"fix":"Evaluate your parsing requirements. If you need robust error reporting, AST manipulation, or to handle highly unconventional JSONC structures, opt for a more feature-rich parser.","message":"This library is intentionally minimalistic and not a 'full-blown' parser. It relies on simple regexes to strip comments and trailing commas before passing the result to `JSON.parse`. For advanced JSONC manipulation, better error messages, or comprehensive parsing, consider libraries like `jsonc-simple-parser`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that the JSON content, *after* comments and trailing commas are removed, conforms strictly to the JSON specification (RFC 8259). Any non-standard JSON syntax will result in `JSON.parse` errors.","message":"After `tiny-jsonc` performs its initial stripping of comments and trailing commas, the resulting string is parsed by the native `JSON.parse` function. This means that the library inherits all the strictness and limitations of standard JSON parsing regarding other syntax rules (e.g., specific string escaping, number formats).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If encountering unexpected parsing errors with complex JSONC structures, verify the input format. For maximum robustness with highly varied or potentially malformed inputs, a more sophisticated parser that builds an Abstract Syntax Tree (AST) might be necessary.","message":"The regex-based stripping mechanism may not perfectly handle all highly unusual, deeply nested, or extremely malformed JSONC comment edge cases. While effective for common patterns, complex or ambiguous comment placements could potentially lead to unexpected parsing failures or incorrect output compared to a full, tokenizing parser.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.2':27 'advanc':92,137 'altern':144 'api':95 'approach':35 'base':34 'blown':107 'bundl':69 'cadenc':123 'capabl':139 'clean':50 'code':84 'comma':43,155,156 'comment':22,39,153 'comprehens':100 'critic':87 'current':24 'depend':82 'design':15 'develop':129,130 'direct':55,142 'emphas':124 'employ':29 'environ':79 'error':97,134 'explicit':141 'extrem':9 'featur':102,128 'final':62 'first':37 'focus':115 'footprint':85 'found':103 'full':106 'full-blown':105 'function':60 'handl':135 'input':47 'instanti':64 'javascript':11,150 'json':20,152 'json.parse':59 'jsonc':2,6,19,46,93,147,151 'jsonc-simple-pars':146 'librari':14,110 'lightweight':10 'like':145 'mainten':120 'maintenance-ori':119 'make':74 'manipul':94 'messag':98 'method':66 'minim':31,81 'nativ':58 'natur':113 'need':131 'object':63 'offer':91 'oper':72 'orient':121 'pars':18,101,138,158 'parser':3,108,149,157 'particular':76 'pass':54 'priorit':67 'rapid':127 'regex':33 'regex-bas':32 'releas':122 'reliabl':125 'rich':96 'robust':133 'scope':116 'simpl':148 'simplic':73 'size':70 'small':68 'specif':16 'stabl':112 'string':23,48,51 'strip':38 'suggest':117 'suitabl':77 'tini':1,5 'tiny-jsonc':4 'trail':42,154 'typescript':13,159 'version':26","created_at":"2026-04-20T01:58:06.233629+00:00","updated_at":"2026-04-20T01:58:06.233629+00:00","problems":[{"fix":"Inspect the JSONC input around the indicated position (X) for unusual comment formatting or edge cases that the regex might miss. Ensure comments follow standard JSONC syntax (`//` for line, `/* */` for block comments).","cause":"The `tiny-jsonc` parser failed to correctly strip a comment from the input string, leading `JSON.parse` to encounter a comment delimiter (like `//` or `/*`) which is invalid in standard JSON.","error":"SyntaxError: Unexpected token / in JSON at position X"},{"fix":"Verify the JSONC input around the indicated position for correctly placed commas. `tiny-jsonc` specifically targets *trailing* commas; other misplaced commas will still cause errors from `JSON.parse`.","cause":"A comma was present in the JSONC input at a position where `JSON.parse` does not expect it (e.g., not as a separator between object properties or array elements). This typically occurs if `tiny-jsonc` didn't strip a trailing comma, or if there's an incorrectly placed comma that isn't a trailing comma.","error":"SyntaxError: Unexpected token , in JSON at position X"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/fabiospampinato/tiny-jsonc","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/tiny-jsonc","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}