couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joscha Feth (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COUCHDB-604) _changes feed with ?feed=continuous does not return valid JSON
Date Mon, 21 Dec 2009 10:25:18 GMT

    [ https://issues.apache.org/jira/browse/COUCHDB-604?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12793146#action_12793146
] 

Joscha Feth commented on COUCHDB-604:
-------------------------------------

Exactly. Each line is valid JSON, but the response itself is not valid JSON.

Now to read the response line by line, a method is needed which reads (from the never ending
feed) until a newline comes and then parses the JSON object. Now to do this, the reading method
needs to block (as it does not know whether the next character is a new line or not). Now
if you take JSON as a structured format, it is much more easy and suitable (because there
is no additional information about newlines, etc. needed) if such a feed is read in a SAX-like
manner, which throws events whenever there are new elements within the feed:

Starting seq
Starting id
Starting changes
Starting rev
Closing rev
...

but such a parser needs the document (or better the stream) to be valid JSON, which the current
ouptut of the cont. feed is not.

> _changes feed with ?feed=continuous does not return valid JSON
> --------------------------------------------------------------
>
>                 Key: COUCHDB-604
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-604
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>    Affects Versions: 0.10
>            Reporter: Joscha Feth
>
> When using the _changes interface via ?feed=continuous the JSON returned is rather 
> a stream of JSON documents than a valid JSON file itself:
> {"seq":38,"id":"f473fe61a8a53778d91c38b23ed6e20f","changes":[{"rev":"9-d3e71c7f5f991b26fe014d884a27087f"}]}
> {"seq":68,"id":"2a574814d61d9ec8a0ebbf43fa03d75b","changes":[{"rev":"6-67179f215e42d63092dc6b2199a3bf51"}],"deleted":true}
> {"seq":70,"id":"75dbdacca8e475f5909e3cc298905ef8","changes":[{"rev":"1-0dee261a2bd4c7fb7f2abd811974d3f8"}]}
> {"seq":71,"id":"09fb03236f80ea0680a3909c2d788e43","changes":[{"rev":"1-a9646389608c13a5c26f4c14c6863753"}]}
> to be valid there needs to be a root element (and then an array with commata) like in
the non-continuous feed:
> {"results":[
> {"seq":38,"id":"f473fe61a8a53778d91c38b23ed6e20f","changes":[{"rev":"9-d3e71c7f5f991b26fe014d884a27087f"}]},
> {"seq":68,"id":"2a574814d61d9ec8a0ebbf43fa03d75b","changes":[{"rev":"6-67179f215e42d63092dc6b2199a3bf51"}],"deleted":true},
> {"seq":70,"id":"75dbdacca8e475f5909e3cc298905ef8","changes":[{"rev":"1-0dee261a2bd4c7fb7f2abd811974d3f8"}]},
> {"seq":71,"id":"09fb03236f80ea0680a3909c2d788e43","changes":[{"rev":"1-a9646389608c13a5c26f4c14c6863753"}]},
> in short this means that if someone does not parse the change events in an object like
manner (e.g. waiting for a line-ending and then parsing the line), but using a SAX-like parser
(throwing events of each new object, etc.) and expecting the response to be JSON (which it
is not, because its not {x:[{},{},{}]} but {}{}{} which is not valid) there is an error thrown.
> I can see, that people doing this line by line might be okay with the above approach,
but the response is not valid JSON and it would be nice if there were a flag to make the response
valid JSON.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message