2.0.1 • Published 8 years ago

query-json v2.0.1

Weekly downloads
100
License
MIT
Repository
github
Last release
8 years ago

Query-JSON

Build Status

Search all occurrences on a given JSON.

$ npm install query-json

API

Import queryJson module:

const queryJson = require("query-json");

Specify both JSON and query regex:

const json = {
  "key_a": {
    "color": "red"
  },
  "key_b": {
    "color": "white"
  },
  "key_c": {
    "color": "blue"
  }
};

Simple query:

const regex = new RegExp('WHITE', 'i');
const result = queryJson.search(json, regex);

console.log(result);
// [ [ 'key_b', 'color' ] ]

Detailed query:

const regex = new RegExp('COLOR', 'i');
const result = queryJson.search(json, regex, {
  details: true
});

console.log(result);
// [ { isKey: true, path: [ 'key_a', 'color' ] },
//   { isKey: true, path: [ 'key_b', 'color' ] },
//   { isKey: true, path: [ 'key_c', 'color' ] } ]

License

MIT

2.0.1

8 years ago

2.0.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago