Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Updated README where it commented on the options you can pass to run(…
Browse files Browse the repository at this point in the history
…...)
  • Loading branch information
Kate Rhodes committed Nov 7, 2008
1 parent db481bd commit 2a23a4c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions README.mkdn
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,22 @@ using the symbol '@' for the current object. Filter expressions are supported vi
$.store.book[?(@.price < 10)].title

Here is a complete overview and a side by side comparison of the JSONPath syntax elements with its XPath counterparts.
<table><tbody><tr class="evn"><td> <strong>XPath</strong> </td><td> <strong>JSONPath</strong> </td><td> <strong>Result</strong> </td></tr>
<table><tr class="evn"><td> <strong>XPath</strong> </td><td> <strong>JSONPath</strong> </td><td> <strong>Result</strong> </td></tr>
<tr class="odd"><td class="lft"><code>/store/book/author</code> </td><td class="lft"><code>$.store.book[*].author</code> </td><td class="lft">the authors of all books in the store </td></tr>
<tr class="evn"><td class="lft"><code>//author</code> </td><td class="lft"><code>$..author</code> </td><td class="lft">all authors </td></tr>

<tr class="odd"><td class="lft"><code>/store/*</code> </td><td class="lft"><code>$.store.*</code> </td><td class="lft">all things in store, which are some books and a red bicycle. </td></tr>
<tr class="evn"><td class="lft"><code>/store//price</code> </td><td class="lft"><code>$.store..price</code> </td><td class="lft">the price of everything in the store. </td></tr>
<tr class="odd"><td class="lft"><code>//book[3]</code> </td><td class="lft"><code>$..book[2]</code> </td><td class="lft">the third book </td></tr>

<tr class="evn"><td class="lft"><code>//book[last()]</code> </td><td class="lft"><code>$..book[(@.length-1)]</code><br>
<code>$..book[-1:]</code> </td><td class="lft">the last book in order. </td></tr>
<tr class="odd"><td class="lft"><code>//book[position()&lt;3]</code> </td><td class="lft"><code>$..book[0,1]</code><br>
<code>$..book[:2]</code> </td><td class="lft">the first two books </td></tr>

<tr class="evn"><td class="lft"><code>//book[isbn]</code> </td><td class="lft"><code>$..book[?(@.isbn)]</code> </td><td class="lft">filter all books with isbn number </td></tr>
<tr class="odd"><td class="lft"><code>//book[price&lt;10]</code> </td><td class="lft"><code>$..book[?(@.price&lt;10)]</code> </td><td class="lft">filter all books cheapier than 10 </td></tr>
<tr class="evn"><td class="lft"><code>//*</code> </td><td class="lft"><code>$..*</code> </td><td class="lft">all Elements in XML document. All members of JSON structure. </td></tr>
<tr class="odd"><td class="lft"><code>???</code> </td><td class="lft"><code>$.store.!</code> </td><td class="lft">all the keys in the store hash (bicycle, book)</td></tr>
</tbody></table>
</table>

XPath has a lot more to offer (Location pathes in not abbreviated syntax, operators and functions) than listed here. Moreover there is a remarkable difference how the subscript operator works in Xpath and JSONPath.

Expand Down Expand Up @@ -122,8 +120,7 @@ JSONPath.pm is a simple perl class, ported from the Javascript and PHP versions,
my $raw_result = $jp->run($json_structure, "$..author"); # either a data structure or zero
print to_json($raw_result, {utf8 => 1, pretty => 1}) . "\n";

The run method also takes an optional third argument, a hash with any options. Currently the only supported option is "result_type" => PATH. Unfortunately it doesn't work correctly in the Perl port yet. If this is something you need please download it and help add this functionality, as it's quite close to working.
results
The run method also takes an optional third argument, a hash with any options. Currently the only supported option is "result_type" which can be "VALUE" or "PATH".

the example results in the following arrays:

Expand Down

0 comments on commit 2a23a4c

Please sign in to comment.