{"id":22070537,"url":"https://github.com/bconnorwhite/parse-json-object","last_synced_at":"2025-07-24T08:36:12.769Z","repository":{"id":57319378,"uuid":"287865773","full_name":"bconnorwhite/parse-json-object","owner":"bconnorwhite","description":"Parse a typed JSON object","archived":false,"fork":false,"pushed_at":"2023-01-29T23:58:28.000Z","size":368,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-05T02:04:00.536Z","etag":null,"topics":["json","node","nodejs","parse","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bconnorwhite.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-16T03:23:55.000Z","updated_at":"2024-03-24T10:37:30.000Z","dependencies_parsed_at":"2023-02-16T02:00:50.231Z","dependency_job_id":null,"html_url":"https://github.com/bconnorwhite/parse-json-object","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bconnorwhite%2Fparse-json-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bconnorwhite%2Fparse-json-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bconnorwhite%2Fparse-json-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bconnorwhite%2Fparse-json-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bconnorwhite","download_url":"https://codeload.github.com/bconnorwhite/parse-json-object/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227422448,"owners_count":17775016,"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":["json","node","nodejs","parse","typescript"],"created_at":"2024-11-30T20:17:07.936Z","updated_at":"2024-11-30T20:17:08.395Z","avatar_url":"https://github.com/bconnorwhite.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--BEGIN HEADER--\u003e\n\u003cdiv id=\"top\" align=\"center\"\u003e\n  \u003ch1\u003eparse-json-object\u003c/h1\u003e\n  \u003ca href=\"https://npmjs.com/package/parse-json-object\"\u003e\n    \u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/v/parse-json-object.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/bconnorwhite/parse-json-object\"\u003e\n    \u003cimg alt=\"TypeScript\" src=\"https://img.shields.io/github/languages/top/bconnorwhite/parse-json-object.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/bconnorwhite/parse-json-object?branch=master\"\u003e\n    \u003cimg alt=\"Coverage Status\" src=\"https://img.shields.io/coveralls/github/bconnorwhite/parse-json-object.svg?branch=master\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cblockquote align=\"center\"\u003eParse a typed JSON object.\u003c/blockquote\u003e\n\n\u003cbr /\u003e\n\n_If I should maintain this repo, please ⭐️_\n\u003ca href=\"https://github.com/bconnorwhite/parse-json-object\"\u003e\n  \u003cimg align=\"right\" alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/bconnorwhite/parse-json-object?label=%E2%AD%90%EF%B8%8F\u0026style=social\"\u003e\n\u003c/a\u003e\n\n_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._\n\u003ca href=\"https://twitter.com/bconnorwhite\"\u003e\n  \u003cimg align=\"right\" alt=\"Twitter\" src=\"https://img.shields.io/twitter/url?label=%40bconnorwhite\u0026style=social\u0026url=https%3A%2F%2Ftwitter.com%2Fbconnorwhite\"\u003e\n\u003c/a\u003e\n\n---\n\u003c!--END HEADER--\u003e\n- Returns `undefined` if unable to parse\n- Returns value if successful\n\n## Installation\n\n```sh\nyarn add parse-json-object\n```\n\n```sh\nnpm install parse-json-object\n```\n\n```sh\npnpm add parse-json-object\n```\n\n## Usage\n\n### Types\n```ts\nimport {\n  parseJSONValue,\n  parseJSONObject,\n  parseJSONArray,\n  parseString\n} from \"parse-json-object\";\n\nparseJSONValue(\"1\"); // 1\nparseJSONValue(\"not valid json\"); // undefined\n\nparseJSONObject('{\"a\": 1}'); // { a: 1 }\nparseJSONArray(\"[1, 2, 3]\"); // [1, 2, 3]\nparseString('\"hello\"'); // \"hello\"\n```\n\nAdditionally, a `parse` function is provided, which takes a function to validate the parsed value. This can be easily used with [zod](https://github.com/colinhacks/zod) to validate more complex types:\n```ts\nimport { parse } from \"parse-json-object\";\nimport z from \"zod\";\n\nconst schema = z.object({\n  a: z.number(),\n  b: z.string()\n});\n\nparse('{ a: 1, b: \"hello\" }', schema); // { a: 1, b: 'hello' }\n\n```\n\nA custom typeguard can also be used:\n\n```ts\nimport { parse } from \"parse-json-object\";\n\nfunction isNumber(value: unknown): value is number {\n  return typeof value === \"number\";\n}\n\nparse(\"1\", isNumber); // 1\nparse(\"not a number\", isNumber); // undefined\n```\n\n\u003c!--BEGIN FOOTER--\u003e\n\n\u003cbr /\u003e\n\n\u003ch2 id=\"dependencies\"\u003eDependencies\u003ca href=\"https://www.npmjs.com/package/parse-json-object?activeTab=dependencies\"\u003e\u003cimg align=\"right\" alt=\"dependencies\" src=\"https://img.shields.io/librariesio/release/npm/parse-json-object.svg\"\u003e\u003c/a\u003e\u003c/h2\u003e\n\n- [is-zod](https://www.npmjs.com/package/is-zod): Typeguard to check if a value matches a zod schema\n- [types-json](https://www.npmjs.com/package/types-json): Type checking for JSON values\n\n\n\u003cbr /\u003e\n\n\u003ch3\u003eDev Dependencies\u003c/h3\u003e\n\n- [autorepo](https://www.npmjs.com/package/autorepo): Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.\n- [zod](https://www.npmjs.com/package/zod): TypeScript-first schema declaration and validation library with static type inference\n\n\n\u003cbr /\u003e\n\n\u003ch2 id=\"license\"\u003eLicense \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg align=\"right\" alt=\"license\" src=\"https://img.shields.io/npm/l/parse-json-object.svg\"\u003e\u003c/a\u003e\u003c/h2\u003e\n\n[MIT](https://opensource.org/licenses/MIT)\n\u003c!--END FOOTER--\u003e\n\n\u003cbr /\u003e\n\n## Related Packages:\n\n- [stringify-json-object](https://www.npmjs.com/package/stringify-json-object): Stringify and format a JSON object\n- [types-json](https://www.npmjs.com/package/types-json): Type checking for JSON objects\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbconnorwhite%2Fparse-json-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbconnorwhite%2Fparse-json-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbconnorwhite%2Fparse-json-object/lists"}