{"id":49581926,"url":"https://github.com/crescendolab-open/parse-json","last_synced_at":"2026-05-03T20:42:35.282Z","repository":{"id":65573075,"uuid":"594969264","full_name":"crescendolab-open/parse-json","owner":"crescendolab-open","description":"A user-friendly wrapper for JSON.parse().","archived":false,"fork":false,"pushed_at":"2024-01-03T09:35:06.000Z","size":33,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-08T14:57:42.855Z","etag":null,"topics":["javascript","json","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@crescendolab/parse-json","language":"TypeScript","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/crescendolab-open.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":null,"support":null}},"created_at":"2023-01-30T05:31:51.000Z","updated_at":"2024-10-29T07:18:07.000Z","dependencies_parsed_at":"2023-02-16T14:16:01.346Z","dependency_job_id":null,"html_url":"https://github.com/crescendolab-open/parse-json","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/crescendolab-open/parse-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crescendolab-open%2Fparse-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crescendolab-open%2Fparse-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crescendolab-open%2Fparse-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crescendolab-open%2Fparse-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crescendolab-open","download_url":"https://codeload.github.com/crescendolab-open/parse-json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crescendolab-open%2Fparse-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32584651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["javascript","json","typescript"],"created_at":"2026-05-03T20:42:34.234Z","updated_at":"2026-05-03T20:42:35.276Z","avatar_url":"https://github.com/crescendolab-open.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @crescendolab/parse-json\n\nA user-friendly wrapper for `JSON.parse()`.\n\n```ts\n// ✅ Returns type `JsonValue` which is stricter than `unknown`.\n// ✅ Fallback specified value is returned if `input` is not a valid JSON string.\nconst output = parseJson(input, null);\n//    ^? const output: JsonValue\nif (typeof output === \"function\") {\n  output;\n  // ^? const output: never\n}\nif (output === undefined) {\n  output;\n  // ^? const output: never\n}\n\n// ❌ Return with type `any`.\n// ❌ Might throw an error if `input` is not a valid JSON string.\nconst vanillaOutput = JSON.parse(input);\n//    ^? const vanillaOutput: any\n```\n\n## Installation\n\n```sh\npnpm i @crescendolab/parse-json\n```\n\n## Usage\n\n```ts\nimport { parseJson } from \"@crescendolab/parse-json\";\n\nconst input = await loadJson();\nconst output = parseJson(input);\n```\n\n## Options\n\n```ts\nparseJson(input, options);\n```\n\n### `options.fallback`\n\n- Type: `any`\n\nSpecify a fallback value to be returned if it fails to parse `input` as a JSON string.\n\n```ts\nconst input = \"not a valid json string\";\n\n// ✅ Get `undefined` instead of throwing an error.\nconst output = parseJson(input, { fallback: undefined });\n```\n\n### `options.parser`\n\n- Type: `(input: string) =\u003e JsonValue`\n\nSpecify a custom parser function.\n\nFor example, you can use [`json5`](https://github.com/json5/json5) for comments in json or [parse-json](https://github.com/sindresorhus/parse-json) for helpful error messages.\n\n```ts\nimport { parseJson } from \"@crescendolab/parse-json\";\nimport json5 from \"json5\";\n\nconst input = `{\n  // This is a comment\n  \"foo\": \"bar\"\n}`;\n\n// ✅ This will not throw an error.\nconst output = parseJson(input, {\n  parser: json5.parse,\n});\n```\n\n## Create your own parser\n\nYou can create a parser with a custom default options where the options are the same as the `options` argument of `parseJson()`.\n\n```ts\nimport { parseJson } from \"@crescendolab/parse-json\";\n\nconst myParser = parseJson.create(options);\nconst myParser = parseJson.create({ fallback: undefined });\n```\n\n## License\n\nMIT © [Crescendo lab](https://www.cresclab.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrescendolab-open%2Fparse-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrescendolab-open%2Fparse-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrescendolab-open%2Fparse-json/lists"}