{"id":13454680,"url":"https://github.com/sindresorhus/parse-json","last_synced_at":"2025-04-29T14:20:32.030Z","repository":{"id":37396544,"uuid":"41367145","full_name":"sindresorhus/parse-json","owner":"sindresorhus","description":"Parse JSON with more helpful errors","archived":false,"fork":false,"pushed_at":"2025-04-09T09:02:05.000Z","size":57,"stargazers_count":364,"open_issues_count":2,"forks_count":36,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-20T23:33:08.798Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-08-25T14:11:41.000Z","updated_at":"2025-04-15T07:55:49.000Z","dependencies_parsed_at":"2023-11-26T03:04:50.774Z","dependency_job_id":"e9ce1609-73f5-4f3a-be4c-224afea48488","html_url":"https://github.com/sindresorhus/parse-json","commit_stats":{"total_commits":60,"total_committers":15,"mean_commits":4.0,"dds":"0.33333333333333337","last_synced_commit":"5ad65169677db8f164a32dcd08a19bc5ae8426e3"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fparse-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fparse-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fparse-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fparse-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/parse-json/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251112075,"owners_count":21538160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:56.762Z","updated_at":"2025-04-29T14:20:32.010Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# parse-json\n\n\u003e 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\u003e 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\u003e 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 (\u003canonymous\u003e)\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\u003e 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 (\u003canonymous\u003e)\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","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","包","Repository","目录","Parsing","Utilities","Number"],"sub_categories":["Parsing","解析","Object / JSON / JSON Schema","解析工具","React Components"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fparse-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fparse-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fparse-json/lists"}