json-scout
Version:
JSON-SCOUT is a library useful to quickly RECURSIVELY search(scout) and extract JSON objects.
106 lines (83 loc) • 3.57 kB
Markdown
<img src="resources/json-scout-logo.png" align="left" width="150" height="150">
This package can be download via Node, NPM using below command
```
npm install json-scout
```
```
npm test
```
```
// Import JSON SCOUT
const { JsonScout } = require("json-scout");
/**
* initialize by creating an Object of JsonScout by
* passing your JSON object/string to constructor
**/
const jScout = new JsonScout(<YOUR_JSON_OBJ>);
// Access function on the create JsonScout object
jScout.scoutOneByKey("<KEY_SEARCH>");
jScout.scoutAllByKey("<KEY_SEARCH>");
jScout.scoutOneByValue("<VALUE_SEARCH>");
jScout.scoutAllByKey("<VALUE_SEARCH>");
```
```
// Import JSON SCOUT
var js = require("json-scout")
/**
* initialize by creating an Object of JsonScout by
* passing your JSON object/string to constructor
**/
var jScout = new js.JsonScout(<YOUR_JSON_OBJ>);
// Access function on the created JsonScout object
jScout.scoutOneByKey("<KEY_SEARCH>");
jScout.scoutAllByKey("<KEY_SEARCH>");
jScout.scoutOneByValue("<VALUE_SEARCH>");
jScout.scoutAllByKey("<VALUE_SEARCH>");
```
- Constructor to initialize the Json Scout.
- Luckily it can take both object and string.
- Example: ```const jScout = new JsonScout('[{"name": "Kevin", "age": 30}, {"name": "Vanessa", "age": 28}]'); ```
- RECURSIVELY searches the initialized JSON based on KEY
- Returns the First Object containing the searched KEY.
- Example: ``` jScout.scoutOneByKey("name"); ```
- Result: ``` {"name": "Kevin", "age": 30} ```
- RECURSIVELY searches the initialized JSON based on KEY
- Returns ALL the Objects containing the searched KEY.
- Example: ``` jScout.scoutAllByKey("name"); ```
- Result: ``` [{"name": "Kevin", "age": 30}, {"name": "Vanessa", "age": 28}] ```
- RECURSIVELY searches the initialized JSON based on VALUE
- Returns the First Object containing the searched VALUE.
- Example: ``` jScout.scoutAllByValue("Vanessa"); ```
- Result: ``` {"name": "Vanessa", "age": 28} ```
- RECURSIVELY searches the initialized JSON based on VALUE
- Returns ALL the Objects containing the searched VALUE.
- Example: ``` jScout.scoutAllByValue(28); ```
- Result: ``` [{"name": "Vanessa", "age": 28}] ```
- RECURSIVELY searches the initialized JSON based on provided KEY and VALUE
- Returns the First Object containing the searched KEY and VALUE.
- Example: ``` jScout.scoutOneByKeyValue("age", 28); ```
- Result: ``` {"name": "Vanessa", "age": 28} ```
- RECURSIVELY searches the initialized JSON based on KEY and VALUE
- Returns ALL the Objects containing the searched KEY and VALUE.
- Example: ``` jScout.scoutAllByKeyValue("age", 28); ```
- Result: ``` [{"name": "Vanessa", "age": 28}] ```