{"id":13516927,"url":"https://github.com/RyanMarcus/dirty-json","last_synced_at":"2025-03-31T07:30:40.383Z","repository":{"id":21482278,"uuid":"24801041","full_name":"RyanMarcus/dirty-json","owner":"RyanMarcus","description":"A parser for invalid JSON","archived":false,"fork":false,"pushed_at":"2024-06-01T15:08:04.000Z","size":277,"stargazers_count":316,"open_issues_count":13,"forks_count":30,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-23T20:01:45.309Z","etag":null,"topics":["javascript","json","parse","resiliency"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RyanMarcus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-04T20:42:22.000Z","updated_at":"2025-02-11T15:03:05.000Z","dependencies_parsed_at":"2024-06-18T13:45:39.801Z","dependency_job_id":"1385ddef-b573-4fa1-b0b7-c4dd77b9e13c","html_url":"https://github.com/RyanMarcus/dirty-json","commit_stats":{"total_commits":149,"total_committers":5,"mean_commits":29.8,"dds":"0.18120805369127513","last_synced_commit":"215fa3254f12fa279c5affcd7180d39de182faee"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMarcus%2Fdirty-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMarcus%2Fdirty-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMarcus%2Fdirty-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMarcus%2Fdirty-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyanMarcus","download_url":"https://codeload.github.com/RyanMarcus/dirty-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246432888,"owners_count":20776480,"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":["javascript","json","parse","resiliency"],"created_at":"2024-08-01T05:01:27.359Z","updated_at":"2025-03-31T07:30:39.847Z","avatar_url":"https://github.com/RyanMarcus.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# dirty-json\n\n[ ![Codeship Status for RyanMarcus/dirty-json](https://codeship.com/projects/cbc19870-2e42-0132-d30c-4adef3b19db7/status)](https://www.codeship.io/projects/39346)  [![Coverage Status](https://coveralls.io/repos/github/RyanMarcus/dirty-json/badge.svg?branch=master)](https://coveralls.io/github/RyanMarcus/dirty-json?branch=master) ![NPM version](https://badge.fury.io/js/dirty-json.svg)\n\n\n[ ![AGPL](http://www.gnu.org/graphics/agplv3-155x51.png) ](http://www.gnu.org/licenses/agpl-3.0.en.html)\n\n\n```\nnpm install dirty-json\n```\n\n\nA JSON parser that tries to handle non-conforming or otherwise invalid JSON.\n\nYou can play around with a demo here: [http://rmarcus.info/dirty-json/](http://rmarcus.info/dirty-json)\n\nYou might also be interested in [my blog post about the parser](http://rmarcus.info/blog/2014/10/05/dirty-json-parser.html).\n\nTurn this:\n\n    [5, .5, 'single quotes', \"quotes in \"quotes\" in quotes\"]\n\nInto this:\n\n    [5,0.5,\"single quotes\",\"quotes in \\\"quotes\\\" in quotes\"]\n\n## Why?\nWe all love JSON. But sometimes, out in that scary place called \"the real world\", we see something like this:\n\n    { \"user\": \"\u003cdiv class=\"user\"\u003eRyan\u003c/div\u003e\" }\n\nOr even something like this:\n\n    { user: '\u003cdiv class=\"user\"\u003e\n\tRyan\n\t\u003c/div\u003e' }\n\nWhile these are obviously cringe-worthy, we still want a way to parse them. `dirty-json` provides a library to do exactly that.\n\n## Examples\n`dirty-json` does not require object keys to be quoted, and can handle single-quoted value strings.\n\n```javascript\nconst dJSON = require('dirty-json');\nconst r = dJSON.parse(\"{ test: 'this is a test'}\")\nconsole.log(JSON.stringify(r));\n\n// output: {\"test\":\"this is a test\"}\n```\n\n`dirty-json` can handle embedded quotes in strings.\n\n```javascript\nconst dJSON = require('dirty-json');\nconst r = dJSON.parse('{ \"test\": \"some text \"a quote\" more text\"}');\nconsole.log(JSON.stringify(r));\n\n// output: {\"test\":\"some text \\\"aquote\\\" more text\"}\n```\n\n`dirty-json` can handle newlines inside of a string.\n\n```javascript\nconst dJSON = require('dirty-json');\nconst r = dJSON.parse('{ \"test\": \"each \\n on \\n new \\n line\"}');\nconsole.log(JSON.stringify(r));\n\n// output: {\"test\":\"each \\n on \\n new \\n line\"}\n```\n\nOptionally, `dirty-json` can handle duplicate keys differently from standard JSON.\n\n```javascript\nconst dJSON = require('dirty-json');\nconst r = dJSON.parse('{\"key\": 1, \"key\": 2, \\'key\\': [1, 2, 3]}');\nconsole.log(JSON.stringify(r));\n// output: {\"key\": [1, 2, 3]}\n\nconst r = dJSON.parse('{\"key\": 1, \"key\": 2, \\'key\\': [1, 2, 3]}', {\"duplicateKeys\": true});\nconsole.log(JSON.stringify(r));\n// output: { key: { value: { value: 1, next: 2 }, next: [ 1, 2, 3 ] } }\n```\n\n## But what about THIS ambiguous example?\nSince `dirty-json` is handling malformed JSON, it will not always produce the result that you \"think\" it should. That's why you should only use this when you absolutely need it. Malformed JSON is malformed for a reason.\n\n## How does it work?\nCurrently `dirty-json` uses a lexer [powered by lex](https://github.com/aaditmshah/lexer) and a hand-written `LR(1)` parser. It shouldn't be used in any environment that requires reliable or fast results.\n\n## Security concerns\n\nThis package makes heavy use of regular expressions in its lexer. As a result, it may be vulnerable to a [REDOS attack](https://snyk.io/blog/redos-and-catastrophic-backtracking). Versions prior to `0.5.1` and after `0.0.5` were *definitely* vulnerable (thanks to [Jamie Davis](http://people.cs.vt.edu/~davisjam/) for pointing this out). I believe version `0.5.1` and later are safe, but since I do not know of any tool to verify a RegEx, I can't prove it. \n\n## Acknowledgements\nThanks to user [Moai-](https://github.com/Moai-) and [0x0a0d](https://github.com/0x0a0d)for fixing array prototype leakage.\n\n## License\n\u003e Copyright 2020, 2018, 2016, 2015, 2014 Ryan Marcus\n\u003e dirty-json is free software: you can redistribute it and/or modify\n\u003e it under the terms of the GNU Affero General Public License as published by\n\u003e the Free Software Foundation, either version 3 of the License, or\n\u003e (at your option) any later version.\n\u003e \n\u003e dirty-json is distributed in the hope that it will be useful,\n\u003e but WITHOUT ANY WARRANTY; without even the implied warranty of\n\u003e MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\u003e GNU Affero General Public License for more details.\n\u003e \n\u003e You should have received a copy of the GNU Affero General Public License\n\u003e along with dirty-json.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanMarcus%2Fdirty-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRyanMarcus%2Fdirty-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanMarcus%2Fdirty-json/lists"}