{"name":"parse-json","version":"8.2.0","description":"Parse JSON with more helpful errors","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/parse-json.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && c8 ava && tsd"},"keywords":["parse","json","graceful","error","message","humanize","friendly","helpful","string"],"dependencies":{"@babel/code-frame":"^7.26.2","index-to-position":"^1.0.0","type-fest":"^4.37.0"},"devDependencies":{"ava":"^6.2.0","c8":"^10.1.3","outdent":"^0.8.0","strip-ansi":"^7.1.0","tsd":"^0.31.2","xo":"^0.60.0"},"_id":"parse-json@8.2.0","gitHead":"6a7bae72889ff172cb44d58223097abb67e9f8c2","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/parse-json/issues"},"homepage":"https://github.com/sindresorhus/parse-json#readme","_nodeVersion":"23.6.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-eONBZy4hm2AgxjNFd8a4nyDJnzUAH0g34xSQAwWEVGCjdZ4ZL7dKZBfq267GWP/JaS9zW62Xs2FeAdDvpHHJGQ==","shasum":"794a590dcf54588ec2282ce6065f15121fa348a0","tarball":"http://registry-npm.ywwl.com/parse-json/download/parse-json-8.2.0.tgz","fileCount":5,"unpackedSize":11195,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDazbj+P3sIZxgXp4MuxHD2aOHKSvCg6ti/qfSoetn8yAiAVAE8jUmiddf+080GuYsGSXe9+HngV5lgevjSib2aJSg=="}],"size":3534,"noattachment":false,"key":"/parse-json/-/parse-json-8.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parse-json_8.2.0_1742543868476_0.09362295905957718"},"_hasShrinkwrap":false,"readme":"# parse-json\n\n> Parse JSON with more helpful errors\n\n## Install\n\n```sh\nnpm install parse-json\n```\n\n## Usage\n\n```js\nimport parseJson, {JSONError} from 'parse-json';\n\nconst json = '{\\n\\t\"foo\": true,\\n}';\n\n\nJSON.parse(json);\n/*\nSyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)\n*/\n\n\nparseJson(json);\n/*\nJSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)\n\n  1 | {\n  2 |   \"foo\": true,\n> 3 | }\n    | ^\n*/\n\n\nparseJson(json, 'foo.json');\n/*\nJSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1) in foo.json\n\n  1 | {\n  2 |   \"foo\": true,\n> 3 | }\n    | ^\n  fileName: 'foo.json',\n  [cause]: SyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)\n      at JSON.parse (<anonymous>)\n      at ...\n*/\n\n\n// You can also add the filename at a later point\ntry {\n\tparseJson(json);\n} catch (error) {\n\tif (error instanceof JSONError) {\n\t\terror.fileName = 'foo.json';\n\t}\n\n\tthrow error;\n}\n/*\nJSONError: Expected double-quoted property name in JSON at position 16 (line 3 column 1) in foo.json\n\n  1 | {\n  2 |   \"foo\": true,\n> 3 | }\n    | ^\n\n  fileName: 'foo.json',\n  [cause]: SyntaxError: Expected double-quoted property name in JSON at position 16 (line 3 column 1)\n      at JSON.parse (<anonymous>)\n      at ...\n*/\n```\n\n## API\n\n### parseJson(string, reviver?, filename?)\n\nThrows a `JSONError` when there is a parsing error.\n\n#### string\n\nType: `string`\n\n#### reviver\n\nType: `Function`\n\nPrescribes how the value originally produced by parsing is transformed, before being returned. See [`JSON.parse` docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter\n) for more.\n\n#### filename\n\nType: `string`\n\nThe filename displayed in the error message.\n\n### JSONError\n\nExposed for `instanceof` checking.\n\n#### fileName\n\nType: `string`\n\nThe filename displayed in the error message.\n\n#### codeFrame\n\nType: `string`\n\nThe printable section of the JSON which produces the error.\n\n#### rawCodeFrame\n\nType: `string`\n\nThe raw version of `codeFrame` without colors.\n","publish_time":1742543868662,"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_cnpm_publish_time":1742543868662,"dist-tags":{"latest":"8.3.0"}}