https://github.com/bjorg/jdoc
Turn JSON objects into queryable documents
https://github.com/bjorg/jdoc
Last synced: over 1 year ago
JSON representation
Turn JSON objects into queryable documents
- Host: GitHub
- URL: https://github.com/bjorg/jdoc
- Owner: bjorg
- License: mit
- Created: 2010-12-22T15:13:04.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-06-21T15:53:36.000Z (about 15 years ago)
- Last Synced: 2025-02-24T07:09:23.771Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 3.51 MB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
jDoc (v0.2)
===========
*Turn JSON objects into queryable documents*
jDoc is a lightweight Javascript class which provides querying capabilities over JSON objects.
Features
--------
* recursive pattern matching
* selection filtering
* selection iterating
* document navigation
Using jDoc
-----------
jDoc uses a fluid interface to query for nested objects in a JSON document. Selections can
be refined by filtering and then iterated over.
Example 1: Getting the text value of the first selected node
------------------------------------------------------------
var jdoc = new jDoc(json);
// obtain the text of the first title node inside a book node
var result = jdoc.select('book/title').text();
// or you can use the shorthand form
var result = jdoc.text('book/title');
Example 2: Finding the text value of all selected nodes
-------------------------------------------------------
var jdoc = new jDoc(json);
// obtain the text of all title nodes inside of all book nodes
var result = '';
jdoc.select('book/title').each(function(cur) {
result += 'title: ' + cur.text() + '\n';
});
Selection Methods
-----------------
* jdoc.select(selector)
* jdoc.match(string | regexp | function, [recursive])
* jdoc.attributes()
* jdoc.elements()
Item Methods
------------
* jdoc.exists([selector])
* jdoc.value([selector])
* jdoc.text([selector])
Collection Methods
------------------
* jdoc.any()
* jdoc.first()
* jdoc.next()
* jdoc.each(function(jdoc) [, context])
* jdoc.get(index)
* jdoc.count()
* jdoc.where(function(jdoc) [, context])
* jdoc.union(jdoc)
* jdoc.map(function(jdoc) [, context])
Compatibility
-------------
* Firefox
* IE
* Chrome
Update Log
----------
* 0.1 - Initial release
* 0.2 - Additionanl overloads which take selector; removed jQuery dependency; improved method names:
'map()' instead of 'select()', 'exists()' instead of 'hasValue()', 'value()' instead of 'json()', and 'select()' instead of '$()'