Lightweight JavaScript library that enables client-side searches of JSON objects. Allows search for objects, keys and values within a JSON string.
Perform simple searches of nodes by allowing to specify key or value to find all matches or use of available methods to validate a JSON structure, get objects, keys or values of a JSON string.
If need a robust or more complex JSON search library, take look to JSONPath or DefiantJS. PursuitJS is intended to do simple searches.
PursuitJS is a build-in merged modification of find-in-json.js by iwek.
Download and include the library into your project by reference:
<script src="../dist/pursuit.min.js" type="text/javascript"></script>
First, parse your JSON string
var jsonString = '{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","ID":"44","str":"SGML","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}';
var data = JSON.parse(jsonString);
var isValid = Pursuit.Validate(json);
- Get objects that match key and value
var results = Pursuit.Objects(data,'ID','SGML');
- Get objects that match specific key
var results = Pursuit.Objects(data,'ID','');
- Get objects that match specific value
var results = Pursuit.Objects(data,'','SGML');
- Get values from any key
var results = Pursuit.Values(data,'ID');
- Get keys by searching specific values
var results = Pursuit.Keys(data,'SGML');
This project is under MIT License - see LICENSE for details.