https://github.com/oldhammade/jpath
JPath is a simple lightweight Javascript Class which provides an XPath-like querying ability to JSON objects, extending the great work by bluelinecity.com
https://github.com/oldhammade/jpath
Last synced: about 2 months ago
JSON representation
JPath is a simple lightweight Javascript Class which provides an XPath-like querying ability to JSON objects, extending the great work by bluelinecity.com
- Host: GitHub
- URL: https://github.com/oldhammade/jpath
- Owner: OldhamMade
- License: other
- Created: 2011-01-19T08:18:51.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2013-07-31T09:01:43.000Z (almost 12 years ago)
- Last Synced: 2025-02-27T21:30:26.841Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 824 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JPath
=====XPath for JSON
--------------JPath is a simple lightweight Javascript Class which provides an XPath-like querying ability to JSON objects. This project extends the great work done by Bryan English at (bluelinecity.com)[http://bluelinecity.com].
Usage
-----var jpath = new JPath( myjsonobj );
var somevalue = jpath.$('book/title').json; //results in title
//or
var somevalue = jpath.query('book/title'); //results in titleSupported XPath Syntax:
-----------------------From the original library:
/tagname
//tagname
tagname
* wildcard
[] predicates
operators ( >=, ==, <= )
array selection
..
*
and, or
nodename[0]
nodename[last()]
nodename[position()]
nodename[last()-1]
nodename[somenode > 3]/node
nodename[count() > 3]/node
nodename[...][...]Additional syntax:
- **is null:** `nodename[is null]`
- **is not null:** `nodename[is not null]`
- **exists():** `nodename[exists(nodename)]`
- **matches():** `nodename[matches(nodename, '^regex$')]`
- **starts-with():** `nodename[starts-with(nodename, 'string')]`
- **ends-with():** `nodename[ends-with(nodename, 'string')]`Array-based queries:
- **in:** `nodename[x in (1,2,"foo","bar")]`
- **has:** `nodename[has "foo"]`
- **empty:** `nodename[emptyarray is empty]`
- **not empty:** `nodename[emptyarray is not empty]`For more examples please see the unit tests.