This module sort of provides some selector to choose portions from a JSON object. These can be helpful in lot ways i.e. when you need to pass a selective data from database to browser.

You can see examples from twitter REST api which yields response based on queries.

First things first, do npm install json-mask

    var jMask = require('json-mask');

Supported selectors

  • a,b,c comma-separated list will select multiple fields
  • a/b/c path will select a field from its parent
  • a(b,c) sub-selection will select many fields from a parent
  • a/*/c the star * wildcard will select all items in a field

Based on description here

Basic Usage

    var data = {name: {first: 'john', middle: 'williams', last:'doe'}, age:33, address: {state: 'US', city: 'ny'}}

    jMask(data,'name')
    { name: { first: 'john', last: 'doe' } }

    jMask(data,'name/first,address/city')
    { name: { first: 'john' },  address: {city: 'ny'}}

    jMask(data,'name(last,middle)')
    { name: { last: 'doe', middle: 'williams' } }

    jMask(data,'name/first,age')
    { name: { first: 'john' }, age: 33 }