{"name":"json-parse-even-better-errors","version":"5.0.0","keywords":["JSON","parser"],"author":{"name":"GitHub Inc."},"license":"MIT","_id":"json-parse-even-better-errors@5.0.0","maintainers":[{"name":"gar","email":"gar+npm@danger.computer"},{"name":"saquibkhan","email":"saquibkhan@github.com"},{"name":"npm-cli-ops","email":"npm-cli+bot@github.com"},{"name":"reggi","email":"reggi@github.com"},{"name":"hashtagchris","email":"hashtagchris@github.com"},{"name":"owlstronaut","email":"owlstronaut@github.com"}],"homepage":"https://github.com/npm/json-parse-even-better-errors#readme","bugs":{"url":"https://github.com/npm/json-parse-even-better-errors/issues"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"],"check-coverage":true},"dist":{"shasum":"93c89f529f022e5dadc233409324f0167b1e903e","tarball":"http://registry-npm.ywwl.com/json-parse-even-better-errors/download/json-parse-even-better-errors-5.0.0.tgz","fileCount":4,"integrity":"sha512-ZF1nxZ28VhQouRWhUcVlUIN3qwSgPuswK05s/HIaoetAoE/9tngVmCHjSxmSQPav1nd+lPtTL0YZ/2AFdR/iYQ==","signatures":[{"sig":"MEUCIES8IbIvrYRgOXetGgB3FM4OjAfVx0Pcsrt62SdL09cOAiEAlh5+DqMWUu59q+iQyvfdHWF28TMwYE4PFW10ePfKtZo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/json-parse-even-better-errors@5.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":9961,"size":4485,"noattachment":false,"key":"/json-parse-even-better-errors/-/json-parse-even-better-errors-5.0.0.tgz"},"main":"lib/index.js","engines":{"node":"^20.17.0 || >=22.9.0"},"gitHead":"ceb17416dd2d7b27a1d8983ce72b78ad33bb320b","scripts":{"lint":"npm run eslint","snap":"tap","test":"tap","eslint":"eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"","lintfix":"npm run eslint -- --fix","postlint":"template-oss-check","posttest":"npm run lint","template-oss-apply":"template-oss-apply --force"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:81004c3d-a27a-42f7-a842-20a21d713263"}},"repository":{"url":"git+https://github.com/npm/json-parse-even-better-errors.git","type":"git"},"_npmVersion":"11.6.2","description":"JSON.parse with context information on error","directories":{},"templateOSS":{"publish":true,"version":"4.27.1","//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten."},"_nodeVersion":"22.20.0","_hasShrinkwrap":false,"devDependencies":{"tap":"^16.3.0","@npmcli/template-oss":"4.27.1","@npmcli/eslint-config":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/json-parse-even-better-errors_5.0.0_1761146751085_0.8389742140275769","host":"s3://npm-registry-packages-npm-production"},"readme":"# json-parse-even-better-errors\n\n[`json-parse-even-better-errors`](https://github.com/npm/json-parse-even-better-errors)\nis a Node.js library for getting nicer errors out of `JSON.parse()`,\nincluding context and position of the parse errors.\n\nIt also preserves the newline and indentation styles of the JSON data, by\nputting them in the object or array in the `Symbol.for('indent')` and\n`Symbol.for('newline')` properties.\n\n## Install\n\n`$ npm install --save json-parse-even-better-errors`\n\n## Table of Contents\n\n* [Example](#example)\n* [Features](#features)\n* [Contributing](#contributing)\n* [API](#api)\n  * [`parse`](#parse)\n\n### Example\n\n```javascript\nconst parseJson = require('json-parse-even-better-errors')\n\nparseJson('\"foo\"') // returns the string 'foo'\nparseJson('garbage') // more useful error message\nparseJson.noExceptions('garbage') // returns undefined\n```\n\n### Features\n\n* Like JSON.parse, but the errors are better.\n* Strips a leading byte-order-mark that you sometimes get reading files.\n* Has a `noExceptions` method that returns undefined rather than throwing.\n* Attaches the newline character(s) used to the `Symbol.for('newline')`\n  property on objects and arrays.\n* Attaches the indentation character(s) used to the `Symbol.for('indent')`\n  property on objects and arrays.\n\n## Indentation\n\nTo preserve indentation when the file is saved back to disk, use\n`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and\nif you want to preserve windows `\\r\\n` newlines, replace the `\\n` chars in\nthe string with `data[Symbol.for('newline')]`.\n\nFor example:\n\n```js\nconst txt = await readFile('./package.json', 'utf8')\nconst data = parseJsonEvenBetterErrors(txt)\nconst indent = Symbol.for('indent')\nconst newline = Symbol.for('newline')\n// .. do some stuff to the data ..\nconst string = JSON.stringify(data, null, data[indent]) + '\\n'\nconst eolFixed = data[newline] === '\\n' ? string\n  : string.replace(/\\n/g, data[newline])\nawait writeFile('./package.json', eolFixed)\n```\n\nIndentation is determined by looking at the whitespace between the initial\n`{` and `[` and the character that follows it.  If you have lots of weird\ninconsistent indentation, then it won't track that or give you any way to\npreserve it.  Whether this is a bug or a feature is debatable ;)\n\n### API\n\n#### <a name=\"parse\"></a> `parse(txt, reviver = null, context = 20)`\n\nWorks just like `JSON.parse`, but will include a bit more information when\nan error happens, and attaches a `Symbol.for('indent')` and\n`Symbol.for('newline')` on objects and arrays.  This throws a\n`JSONParseError`.\n\n#### <a name=\"parse\"></a> `parse.noExceptions(txt, reviver = null)`\n\nWorks just like `JSON.parse`, but will return `undefined` rather than\nthrowing an error.\n\n#### <a name=\"jsonparseerror\"></a> `class JSONParseError(er, text, context = 20, caller = null)`\n\nExtends the JavaScript `SyntaxError` class to parse the message and provide\nbetter metadata.\n\nPass in the error thrown by the built-in `JSON.parse`, and the text being\nparsed, and it'll parse out the bits needed to be helpful.\n\n`context` defaults to 20.\n\nSet a `caller` function to trim internal implementation details out of the\nstack trace.  When calling `parseJson`, this is set to the `parseJson`\nfunction.  If not set, then the constructor defaults to itself, so the\nstack trace will point to the spot where you call `new JSONParseError`.\n","publish_time":1761146751261,"_cnpm_publish_time":1761146751261,"dist-tags":{"latest":"6.0.0"}}