json-scout
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

json-scout : A scout for your JSON

 

JSON-SCOUT is a useful library to RECURSIVELY search(scout) and extract JSON objects.

 

Search could be performed based on a KEY or VALUE or BOTH.

 

Initialization of the JsonScout can be done either by JSON string or Json Object

 

Installation

This package can be download via Node, NPM using below command

npm install json-scout
npm test

Usage

Typescript

  // 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>");
  

NodeJs

// 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>");

Functions

JsonScout(<YOUR_JSON_OBJ>: object/string)

  • 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}]');

scoutOneByKey(<SEARCH_KEY>: string)

  • 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}

scoutAllByKey(<SEARCH_KEY>: string)

  • 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}]

scoutOneByValue(<SEARCH_VALUE>: string)

  • 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}

scoutAllByValue(<SEARCH_VALUE>: string)

  • 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}]

scoutOneByKeyValue(<SEARCH_VALUE>: string)

  • 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}

scoutAllByKeyValue(<SEARCH_VALUE>: string)

  • 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}]

Package Sidebar

Install

npm i json-scout

Weekly Downloads

229

Version

1.2.0

License

Apache-2.0

Unpacked Size

195 kB

Total Files

12

Last publish

Collaborators

  • kishor-p