# jsonquerybuilder

> NPM Package which supports building JSON queries

Latest version **0.0.3** (published 2021-08-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install jsonquerybuilder
pnpm add jsonquerybuilder
yarn add jsonquerybuilder
bun add jsonquerybuilder
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-08-03 |
| First published | 2021-08-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | asheesh12 |

## Links

- npm: https://www.npmjs.com/package/jsonquerybuilder
- npm.io page: https://npm.io/package/jsonquerybuilder

## Recent versions

- 0.0.3 (latest) — 2021-08-03
- 0.0.2 — 2021-08-03
- 0.0.1 — 2021-08-03

## README

# JSON Query Builder

jsonQueryBuilder is a javascript project which makes it easier to write long and complex JSON queries 

## Installation

Use in Node.js
```bash
npm install jsonquerybuilder
```

## Usage

```javascript
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"}}]}}}
```

## Methods

### Query 

#### addProperty(path, query, { multiple, overwrite, rank })

###### Description
Adds the specified `query` in an array.

###### Parameters
`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
1. `multiple`  (Boolean) For adding multiple value to the specified path. Note, `query` parameter must be an array if this is set to true.
2. `overwrite` (Boolean) If set to true, the path would be overwritten (the previous value would be replaced).
3. `rank` (Number) This decides ordering  of the `query` 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.


#### setProperty(path, query, { overwrite })

###### Description
Sets the value of the path to the specified `query`

###### Parameters
`path` array of string representing the path where the query will be set  
`query` the query to be set  
`options` Optional fields
1. `overwrite` (Boolean) If set to true, the path would be overwritten (the previous value would be replaced).



#### deleteProperty(path)

###### Description
Deletes the value at the specified `path`.

###### Parameters
`path` array of string representing the path from where the value will be deleted

#### build()

###### Description
Builds and returns the JSON query.



## License
[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/jsonquerybuilder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
