Skip to content
Turn JSON objects into queryable documents
JavaScript Shell
Latest commit 14ace8a Jun 21, 2011 @bjorg added test for a//b selector
Failed to load latest commit information.
.gitignore initial 0.1 release with basic selection/iteration functionality Dec 22, 2010
package.json updated npm package definition Jun 16, 2011

jDoc (v0.2)

Turn JSON objects into queryable documents

jDoc is a lightweight Javascript class which provides querying capabilities over JSON objects.


  • 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 ='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 = '';'book/title').each(function(cur) {
    result += 'title: '  + cur.text() + '\n';

Selection Methods

  • 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.each(function(jdoc) [, context])
  • jdoc.get(index)
  • jdoc.count()
  • jdoc.where(function(jdoc) [, context])
  • jdoc.union(jdoc)
  • [, context])


  • 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 '$()'
Something went wrong with that request. Please try again.