Email: bryan@bluelinecity.com
I try to answer every email I receive the same day however days are hectic now so there’s no telling. All I ask is to give me a couple days to answer. I’ll be posting a forum so as to try and capture the frequently asked questions.
January 28th, 2010 at 12:43 am
foul…. need examples of use, not just jscript, need html, etc.
THANKS!
September 21st, 2011 at 4:24 pm
Hi Bryan,
I spent all day looking for a powerful yet easy-to-use XPath-like JSON query language.
Yours evaluated as top entry (so congrats!).
However, during testing I discovered JPath has problems with nested properties.
I extended your demo ‘library’ JSON dataset by making objects of the chapters of a book (see below) and then tried to query it like this:
var somevalue = jpath.query(‘books[title == "Brief History of time"][0]/chapters[name == "Chapter 1"][0]/contents’);
However that results in null. But when I split the query in two, using the result of the first part to create a new JPath object and use that to query the second part, it works fine:
var somevalue = new JPath(jpath.query(‘books[title == "Brief History of time"][0]‘)).query(‘/chapters[name == "Chapter 1"][0]/contents’); // results in ‘A lot of paragraphs’ which is what I expected.
Can you shed your light on this?
Also, the ‘and’ and ‘or’ operators do not seem to work correctly: when I enter this query:
var somevalue = jpath.query(‘books[title == "Brief History of time" and isbn == "1234-ABCD"][0]‘);
it results in null again.
Here are the data I used:
var library = {
‘name’ :’My Library’,
‘@open’ : ’2007-17-7′,
‘address’ : {
‘city’ : ‘Springfield’,
‘zip’ : ’12345′,
‘state’ : ‘MI’,
‘street’ : ‘Mockingbird Lane’
},
‘books’:[
{
'title' : 'Harry Potter',
'isbn' : '1234-1234',
'category' : 'Childrens',
'available' : '3',
'chapters' : [ 'Chapter 1', 'Chapter 2' ]
},
{
‘title’ : ‘Brief History of time’,
‘isbn’ : ’1234-ABCD’,
‘category’ : ‘Science’,
‘chapters’ : [
{'name': 'Chapter 1',
'contents': 'A lot of paragraphs'
},
{'name': 'Chapter 2',
'contents': 'Also a lot of paragrahps'
}
]
},
{
‘title’ : ‘Lord of the Rings’,
‘isbn’ : ’1234-PPPP’,
‘category’ : ‘Fiction’,
‘chapters’ : [ 'Section 1', 'Section 2' ]
}
],
‘categories’ : [
{'name':'Childrens', 'description':'Childrens books'},
{'name':'Science', 'description':'Books about science'},
{'name':'Fiction', 'description':'Fiction books'}
]};
Thanks in advance,
Paul
September 21st, 2011 at 10:40 pm
Hi Paul, Thanks for reporting this bug. I found a greedy regular expression that was taking up too much of the quoted strings. I just uploaded a bug fixed version of jpath ( 1.0.5 ) that solves this issue.