Great question. A few reasons:

    1. JSON Mask* doesn't alter the structure of the document*. It doesn't 
select elements (like JSONPath or JSONSelect), but rather filters the parts 
of the object that you don't need. To illustrate that point, instead of 
getting "[{a: 1}, {z: 1}]" from the example above, with JSON Mask you get 
"{p: {a: 1}, z: 1}". This is important to me because I made this 
specifically to work with HTTP resources, the structure of which I didn't 
want to change.

    2. It's* faster* for the types of selectors it supports (the syntax is 
simple, so there are only a handful). Take a look at 
http://jsperf.com/jsonpath-vs-jsonmask (61% faster on selecting items from 
an array in Chrome). It can be even faster if you pre-compile the query 
with `jsonMask.compile()` and then use `jsonMask.parse()`. But that, of 
course, only works when you know the query ahead of time.

    3. It has a scary mascot :)

- Yuriy


On Tuesday, July 16, 2013 6:13:52 AM UTC-4, Floby wrote:
>
> Looks nice. But why not choose something like JSONPath for selecting 
> fields ?
>
> On Monday, 15 July 2013 08:59:11 UTC+2, Yuriy Nemtsov wrote:
>>
>> If you send the *"?fields="* query-string to a Google API, you'll get 
>> just the parts of the JSON object from the response that you requested.
>>
>> Now, you can have this same exact feature in your Node.js services. Say 
>> hello to *JSON Mask <https://github.com/nemtsov/json-mask>* and the *Partial 
>> Response Middleware<https://github.com/nemtsov/partial-response-middleware>
>> * for express!
>>
>> *JSON Mask* is a tiny language and an engine for selecting specific 
>> parts of a JS object, hiding/masking the rest. Here's a tiny sample of what 
>> it looks like:
>>
>> var mask = require('json-mask')mask({p: {a: 1, b: 2}, z: 1}, 'p/a,z')  // 
>> {p: {a: 1}, z: 1}
>>
>> *Partial Response Middleware* is an express middleware that will 
>> integrate with your existing services with no additional code if you're 
>> using* res.json() or res.jsonp()* So, instead of getting the entire JSON 
>> object, your services will start being able to respond with partial objects.
>>
>>
>> I'd love to hear what you think about these.
>>
>> - Yuriy
>>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to