Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax errors when parsing #4

Open
flashingpumpkin opened this issue May 6, 2011 · 5 comments
Open

Syntax errors when parsing #4

flashingpumpkin opened this issue May 6, 2011 · 5 comments

Comments

@flashingpumpkin
Copy link

Hi there.

I've come across errors when processing json from a couchdb. I'll use the standard _users database for example.

$ curl "localhost:5984/_users/_all_docs" 
{"total_rows":1,"offset":0,"rows":[
{"id":"_design/_auth","key":"_design/_auth","value":{"rev":"1-c44fb12a2676d481d235523092e0cec4"}}
]}

Now when sending through json, this is the output:

     $ curl "localhost:5984/_users/_all_docs" | json
 {
    "id": "_design/_auth",
    "key": "_design/_auth",
    "value": {
        "rev": "1-c44fb12a2676d481d235523092e0cec4"
    }
}

Here's the debugging output:

$ curl "localhost:5984/_users/_all_docs" | json -d
ex: {
    "stack": "SyntaxError: Unexpected end of input\n    at Object.parse (native)\n    at [object Object].processObjects (/usr/local/lib/node/.npm/json/0.0.8/package/lib/jsonCommand.js:351:31)\n    at Socket.<anonymous> (/usr/local/lib/node/.npm/json/0.0.8/package/lib/jsonCommand.js:443:40)\n    at Socket.emit (events.js:64:17)\n    at Socket._onReadable (net.js:667:31)\n    at IOWatcher.onReadable [as callback] (net.js:177:10)",
    "arguments": [],
    "type": "unexpected_eos",
    "message": "Unexpected end of input"
}
{
    "id": "_design/_auth",
    "key": "_design/_auth",
    "value": {
        "rev": "1-c44fb12a2676d481d235523092e0cec4"
    }
}
ex: {
    "stack": "SyntaxError: Unexpected token ]\n    at Object.parse (native)\n    at [object Object].processObjects (/usr/local/lib/node/.npm/json/0.0.8/package/lib/jsonCommand.js:351:31)\n    at Socket.<anonymous> (/usr/local/lib/node/.npm/json/0.0.8/package/lib/jsonCommand.js:448:18)\n    at Socket.emit (events.js:61:17)\n    at Socket._onReadable (net.js:652:51)\n    at IOWatcher.onReadable [as callback] (net.js:177:10)",
    "arguments": [
        "]"
    ],
    "type": "unexpected_token",
    "message": "Unexpected token ]"
}
@zpoley
Copy link
Owner

zpoley commented May 6, 2011

Hi Alex,

This seems to be an issue with the newlines in the couchdb json. You can try the following command which replaces the newlines with space:

curl "localhost:5984/_users/_all_docs" | tr '\n' ' ' | json

Please let me know if this doesn't solve your problem or if you have other questions.

Thanks,
Zach

@flashingpumpkin
Copy link
Author

Yes, this works. The JSON that CouchDB returns is valid, though and suggests that the parser should take care of this, and not the human.

@flashingpumpkin
Copy link
Author

Liking the app though, and for the time being, I'll just alias json to your quickfix

@zpoley
Copy link
Owner

zpoley commented May 7, 2011

Great! I agree that the parser should handle that. This is one of the corners that I decided to cut the first time around. I will think more about how to handle it.

@marcin-wosinek
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants