{"name":"jsonrepair","description":"Repair a malformed JSON stream","version":"0.1.0","main":"index.js","directories":{"example":"example"},"author":{"name":"Volker Mische","email":"volker.mische@gmail.com","url":"http://vmx.cx/"},"homepage":"https://github.com/vmx/jsonrepair","repository":{"type":"git","url":"git://github.com/vmx/jsonrepair.git"},"bugs":"https://github.com/vmx/jsonrepair/issues","keywords":["JSON","stream","streaming","repair","malformed"],"licenses":[{"type":"MIT","url":"http://github.com/vmx/raw/master/LICENSE"}],"dependencies":{"clarinet":"~0.7.0"},"readme":"jsonrepair\n==========\n\njsonrepair is transforming malformed JSON streams into valid ones. It uses [clarinet](https://github.com/dscape/clarinet/) in the background to do the JSON parsing. Whenever an error occurs, you can handle that and move and with parsing. This is useful when your JSON got automatically generated from some other source, but contains some errors. Things like trailing commas in arrays, or two subsequent commas.\n\n\nDefining rules\n--------------\n\nTo transform the malformed JSON, you need to define rules that should be applied whenever a parsing error occurs. For example when you want to remove a trailing comma in an array, if there is any, the rule would look like this:\n\n    {\n        description: 'Removing trailing comma within array',\n        character: ']',\n        expected: 'VALUE',\n        action: function(parser) {\n            parser.stack.pop();\n            parser.onclosearray();\n            var newState = parser.stack.pop();\n            parser.state = newState;\n        }\n    }\n\nThe `character` defines the character that is currently processed. In case of the trailing comma case, we see an error when the closing bracket `]` is hit.\n\nThe `expected` property defines in which state the error is happening. When a comma within an array was read, the next state is `VALUE` as it expects to read the next value. Here's a list of possible values for the `expected` property:\n\n - **BEGIN**: Something in front of everything (e.g. a header)\n - **OPEN_OBJECT**: Right after the opening bracket of an object\n - **CLOSE_OBJECT**: After the value of a key-value pair (before the comma or the ending bracket)\n - **OPEN_KEY**: Right before the key of an object (after a comma or the opening bracket)\n - **CLOSE_KEY**: Right after the key, *before* the colon\n - **VALUE**:\n   - In an object: After the key, before the value (after the colon)\n   - In an array: After a previous value (after the comma) or right after the opening bracket\n - **OPEN_ARRAY**: Right after the opening bracket of an array\n - **CLOSE_ARRAY**: After the value in an array (before the comma or the ending bracket)\n\n`action` defines what should happen. It's a function that takes the internal clarinet parser as an input. There you can manipulate the current state of the parser to make it move on in the expected way.\n\n\nFull example\n------------\n\n    var fs = require('fs');\n    var RepairStream = require('jsonrepair').RepairStream;\n\n    var repairRules = [{\n        description: 'Removing trailing comma within array',\n        character: ']',\n        expected: 'VALUE',\n        action: function(parser) {\n            parser.stack.pop();\n            parser.onclosearray();\n            var newState = parser.stack.pop();\n            parser.state = newState;\n        }\n    }];\n\n    var input = fs.createReadStream('malformed.json');\n    var repairJson = new RepairStream(repairRules);\n\n    input.pipe(repairJson).pipe(process.stdout);\n\n\nSee the `example/` directory for more examples.\n\n\nLicense\n-------\n\nThe code is licensed under the MIT License.\n","_id":"jsonrepair@0.1.0","dist":{"shasum":"60a8b41456693e7d5f2c6bff9044112721a70d87","tarball":"http://registry-npm.ywwl.com/jsonrepair/download/jsonrepair-0.1.0.tgz","integrity":"sha512-txZscSBY5VGt7nfepq/38ck5uYLLR2SWiCMYKOjiH37kwfhh3dBblJDTfi836SvrUK7J0G4gg8+P8tGznI55bA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEmREcAEe8Y0G2WDbMBelCtzA/LFfvjVX6Q6WV0JBT9GAiBPxLynysiBi3c329fyuaxOj6OKw4KpCqOrlMbms01qFw=="}],"size":3356,"noattachment":false,"key":"/jsonrepair/-/jsonrepair-0.1.0.tgz"},"_npmVersion":"1.1.62","_npmUser":{"name":"vmx","email":"volker.mische@gmail.com"},"maintainers":[{"name":"vmx","email":"volker.mische@gmail.com"}],"publish_time":1353874530940,"_cnpm_publish_time":1353874530940,"dist-tags":{"latest":"3.15.0"}}