Skip to content

slmcassio/query-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published