{"id":16385195,"url":"https://github.com/hua1995116/easy-json-parse","last_synced_at":"2025-03-21T02:31:14.831Z","repository":{"id":57218511,"uuid":"197223033","full_name":"hua1995116/easy-json-parse","owner":"hua1995116","description":"Parse your json safely and easily.","archived":false,"fork":false,"pushed_at":"2019-07-29T12:00:50.000Z","size":11,"stargazers_count":33,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T04:13:57.309Z","etag":null,"topics":["json","parse"],"latest_commit_sha":null,"homepage":"","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/hua1995116.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":"2019-07-16T15:45:42.000Z","updated_at":"2023-06-28T08:15:15.000Z","dependencies_parsed_at":"2022-08-28T21:01:59.729Z","dependency_job_id":null,"html_url":"https://github.com/hua1995116/easy-json-parse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hua1995116%2Feasy-json-parse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hua1995116%2Feasy-json-parse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hua1995116%2Feasy-json-parse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hua1995116%2Feasy-json-parse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hua1995116","download_url":"https://codeload.github.com/hua1995116/easy-json-parse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811386,"owners_count":16884305,"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","parse"],"created_at":"2024-10-11T04:13:56.924Z","updated_at":"2024-10-28T09:07:32.612Z","avatar_url":"https://github.com/hua1995116.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# easy-json-parse\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.org/hua1995116/easy-json-parse\"\u003e\u003cimg src=\"https://travis-ci.org/hua1995116/easy-json-parse.svg?branch=master\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/hua1995116/easy-json-parse\"\u003e\u003cimg src=\"https://codecov.io/gh/hua1995116/easy-json-parse/branch/master/graph/badge.svg\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://npmcharts.com/compare/easy-json-parse?minimal=true\" rel=\"nofollow\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/easy-json-parse.svg\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/easy-json-parse\" rel=\"nofollow\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/easy-json-parse.svg\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/easy-json-parse\" rel=\"nofollow\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/easy-json-parse.svg?style=flat\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nAre you still worried about the long code with `try {} catch {}`? like this:\n\n```javascript\nconst jsonString = 'easy';\nlet json;\n\ntry {\n  json = JSON.parse(jsonString);\n} catch (e) {\n  json = {};\n}\n\nconsole.log(json.xxx);\n```\nor\n```javascript\nconst jsonString = null;\nlet json;\n\ntry {\n  json = JSON.parse(jsonString) || {};\n} catch (e) {\n  json = {};\n}\n\nconsole.log(json.xxx);\n```\n\nNow, no matter whether it is long code or initialization, you don't need to worry.\n\nuse `easy-json-parse` will more easy and safe for `try{} catch{}`.\n\n## Get started\n\n```bash\nnpm i easy-json-parse\n```\n\ncase: initialValue\n\n```javascript\nimport easyParse from 'easy-json-parse';\nconst jsonString = 'easy';\nconst [error, json] = easyParse(jsonString, {initialValue: {}});\n\nconsole.log(json.xxx); // If json is not exist, will return {} safely.\n```\n\ncase: normal\n\n```javascript\nimport easyParse from 'easy-json-parse';\nconst jsonString = '{\"easy\": \"easy\"}';\nconst [error, json] = easyParse(jsonString);\n\nconsole.log(json.easy); // easy\n```\n\ncase: don't need error\n\n```javascript\nimport easyParse from 'easy-json-parse';\nconst jsonString = '{\"easy\": \"easy\"}';\nconst [, json] = easyParse(jsonString);\n\nconsole.log(json.easy); // easy\n```\n\n## Syntax\n\n### Parameters\n\n**text**\n\nthe string to parse as JSON\n\n**options**\n\n`options.reviver(optional)`\n\n- if a function, prescribes how the value originally produced by parsing is transformed, before being returned, more info about this param in [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter)\n\n`options.initialValue(optional)`\n- init value for json.\n\n### Returns\n\nArray [error, value]\n\n# License\n\nMIT\n\nCopyright (c) 2019 蓝色的秋风","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhua1995116%2Feasy-json-parse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhua1995116%2Feasy-json-parse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhua1995116%2Feasy-json-parse/lists"}