Express middleware for filtering-out parts of JSON responses based on the `fields` query-string; à la Google API's Partial Response.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example initial commit Jul 15, 2013
.gitignore initial commit Jul 15, 2013
LICENSE initial commit Jul 15, 2013 fix typo in readme Jul 28, 2013
index.js make req.jsonp optional Aug 4, 2014
package.json package: lint repo Jan 11, 2015

Express Partial Response Middleware NPM version

This Express Middleware will allow you to send a subset of a JSON object instead of an entire object from your HTTP services. To do so, your services will begin accepting the ?fields= query-string that, using a simple language, will specify which fields and sub-feelds to keep and which to ignore.

If you've used the Google APIs, provided a ?fields= query-string to get a Partial Response, and wanted to do the same for your own server, now you can do so with this middleware.

Underneath, this middleware uses json-mask. Use it directly without this middleware if you need more flexibility.


npm install express-partial-response


var express = require('express')
  , partialResponse = require('express-partial-response')
  , app = express()


app.get('/', function (res, res, next) {
      firstName: 'Mohandas'
    , lastName: 'Gandhi'
    , aliases: [{
          firstName: 'Mahatma'
        , lastName: 'Gandhi'
      }, {
          firstName: 'Bapu'


Let's test it:

$ curl 'http://localhost:4000'

$ # Let's just get the first name
$ curl 'http://localhost:4000?fields=lastName'

$ # Now, let's just get the first names directly as well as from aliases
$ curl 'http://localhost:4000?fields=firstName,aliases(firstName)'

Note: take a look at /example.


Look at json-mask for the available syntax of the fields param.


query specifies the query-string to use. Defaults to fields

  query: 'filter'