https://github.com/ecto/knife
Parse shitty JSON!
https://github.com/ecto/knife
Last synced: about 1 year ago
JSON representation
Parse shitty JSON!
- Host: GitHub
- URL: https://github.com/ecto/knife
- Owner: ecto
- Created: 2011-10-27T23:11:02.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2011-10-28T00:17:22.000Z (over 14 years ago)
- Last Synced: 2025-05-06T02:56:05.298Z (about 1 year ago)
- Homepage:
- Size: 89.8 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# knife
Parse JSON that's smushed together

# why?
Imagine you have a TCP server that clients are sending JSON to. At fast paces, you can't know if the end of the message is actually the end of the JSON object.
Instead of searching for a delimiter or control character, why not continually parse it?
# install
npm install knife
# example
````javascript
var knife = require('knife');
var testObj = {
lol: 'wut'
}
var goodJSON = JSON.stringify(testObj),
badJSON = goodJSON + goodJSON;
console.log([
knife.parse(goodJSON),
knife.parse(badJSON)
]);
````
# knife.parse(uglyStuff, debug = false)
will always return
````javascript
{
results: [ {}, {}, ... ],
remainder: ''
}
````