jsonQueryBuilder is a javascript project which makes it easier to write long and complex JSON queries
Use in Node.js
npm install jsonquerybuilder
let { Query } = require('jsonQueryBuilder');
let query = new Query();
query.setProperty(['query', 'sort'], { 'name': 1 });
query.addProperty(['query', 'bool', 'must'], { "match": { "name": "Joe" } } });
console.log(query.build());
// Prints -> {"query":{"sort":{"name":1},"bool":{"must":[{"match":{"name":"Joe"}}]}}}
Adds the specified query
in an array.
path
array of string representing the path where the query will get added on
query
the query which gets added onto the path
options
Optional fields
-
multiple
(Boolean) For adding multiple value to the specified path. Note,query
parameter must be an array if this is set to true. -
overwrite
(Boolean) If set to true, the path would be overwritten (the previous value would be replaced). -
rank
(Number) This decides ordering of thequery
being added. Queries with lower rank will get placed in the starting of the array. If it's not set, the query will get appended at the end of the array.
Sets the value of the path to the specified query
path
array of string representing the path where the query will be set
query
the query to be set
options
Optional fields
-
overwrite
(Boolean) If set to true, the path would be overwritten (the previous value would be replaced).
Deletes the value at the specified path
.
path
array of string representing the path from where the value will be deleted
Builds and returns the JSON query.