lloyd / JSONSelect

CSS-like selectors for JSON
http://jsonselect.org
ISC License
1.59k stars 116 forks source link

decouple matcher from traversal - for streaming filter? #26

Closed dominictarr closed 13 years ago

dominictarr commented 13 years ago

would it be possible to decouple the matcher from the traversal, so that it is possible to use this on objects that are fully created finished yet?

basically, over here https://github.com/Floby/node-json-streams/issues/4 we are working on a streaming JSON parser,

in that process, we are already traversing the object, would it be possible to call part of this module to select what parts of the stream we are interested in?

I presume you would need something like the root object, the current value, and the current path?

cheers, Dominic

lloyd commented 13 years ago

Yo dominic!

So I designed JSONSelect with streaming in mind. I really am excited to someday build fast as hell native stream filtering on top of yajl. That said, the javascript reference implementation here is a complete implementation of the whole JSONSelect selector language, and it would be difficult to adapt it for stream filtering because it includes constructs that need more context (consider the sibling selector, that requires a complete subtree before it can determine if there's a match or not).

On the bright side, If you check out the docs, JSONSelect level 1 is designed to be easy to implement with minimal context, and should be pretty straightforward to implement in a streaming parser: http://jsonselect.org/#docs/levels

This in fact was going to be my strategy with yajl, to start with level 1, and then incrementally add dynamic buffering to handle cases where level 2 or level 3 selectors are used.

hth!

dominictarr commented 13 years ago

okay, interesting,

I should say that I do not intend to implement JSONSelect, but I am interesting in plugging your implementation into a streaming parser.

basically, I'm generating an event whenever an object is complete, at that point the current object, and the path to current object are complete. the stack of ancestor objects may be uncomplete.

okay, so reading the docs there, it looks like you would just ignore the level 2 stuff, just resort that T and U where matched at a given level, then when the parent is complete, you can do the level 2 checks.

what sort of data structure does a JSONSelect expression compile to, and how do you process that against the traversal?

On Sat, Sep 24, 2011 at 2:05 AM, Lloyd Hilaiel < reply@reply.github.com>wrote:

Yo dominic!

So I designed JSONSelect with streaming in mind. I really am excited to someday build fast as hell native stream filtering on top of yajl. That said, the javascript reference implementation here is a complete implementation of the whole JSONSelect selector language, and it would be difficult to adapt it for stream filtering because it includes constructs that need more context (consider the sibling selector, that requires a complete subtree before it can determine if there's a match or not).

On the bright side, If you check out the docs, JSONSelect level 1 is designed to be easy to implement with minimal context, and should be pretty straightforward to implement in a streaming parser: http://jsonselect.org/#docs/levels

This in fact was going to be my strategy with yajl, to start with level 1, and then incrementally add dynamic buffering to handle cases where level 2 or level 3 selectors are used.

hth!

Reply to this email directly or view it on GitHub: https://github.com/lloyd/JSONSelect/issues/26#issuecomment-2180095