Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Dec 17, 2015
1 parent 141a0a4 commit ff6c341
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
54 changes: 50 additions & 4 deletions doc/jsonpath
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,51 @@ basic_json<Char,Alloc> json_query(const basic_json<Char,Alloc>&
</tr>
</tbody>
</table>
<h3 id="filter-expression">Filter expression</h3>
<table>
<thead>
<tr>
<th>Operator</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>==</code></td>
<td>Left is equal to right </td>
</tr>
<tr>
<td><code>!=</code></td>
<td>Left is not equal to right</td>
</tr>
<tr>
<td><code>&lt;</code></td>
<td>Left is less than right</td>
</tr>
<tr>
<td><code>&lt;=</code></td>
<td>Left is less or equal to right</td>
</tr>
<tr>
<td><code>&gt;</code></td>
<td>Left is greater than right</td>
</tr>
<tr>
<td><code>&gt;=</code></td>
<td>Left is greater than or equal to right</td>
</tr>
<tr>
<td><code>&amp;&amp;</code></td>
<td>Left and right</td>
</tr>
<tr>
<td>`</td>
<td>`</td>
<td>Left or right</td>
</tr>
</tbody>
</table>
<p>In this implementation, binary expressions must appear within parentheses.</p>
<h3 id="examples">Examples</h3>
<p>The examples below use the JSON text from <a href="http://goessner.net/articles/JsonPath/">Stefan Goessner&#39;s JsonPath</a> (store.json).</p>
<pre><code>{ &quot;store&quot;: {
Expand Down Expand Up @@ -586,6 +631,11 @@ std::cout &lt;&lt; pretty_print(result) &lt;&lt; std::endl;
</thead>
<tbody>
<tr>
<td><code>$..book.length</code></td>
<td>The number of books</td>
<td><code>length</code> is a property of an array</td>
</tr>
<tr>
<td><code>$.store.book[*].author</code></td>
<td>All authors of books in the store</td>
</tr>
Expand Down Expand Up @@ -646,10 +696,6 @@ std::cout &lt;&lt; pretty_print(result) &lt;&lt; std::endl;
<td>Everything in the store.</td>
</tr>
<tr>
<td><code>$..book.length</code></td>
<td>The number of books</td>
</tr>
<tr>
<td>`$.store.book[ ?((@.author == &#39;Nigel Rees&#39;)</td>
<td>(@.author == &#39;Evelyn Waugh&#39;)) ].title`</td>
<td>The titles of all books by Nigel Rees and Evelyn Waugh</td>
Expand Down
17 changes: 16 additions & 1 deletion src/doc/Reference/jsonpath.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ JSONPath| Description
`?()` |Applies a filter expression.
`()` |Filter expression.

### Filter expression

Operator| Description
--------|--------------------------------
`==` |Left is equal to right
`!=` |Left is not equal to right
`<` |Left is less than right
`<=` |Left is less or equal to right
`>` |Left is greater than right
`>=` |Left is greater than or equal to right
`&&` |Left and right
`||` |Left or right

In this implementation, binary expressions must appear within parentheses.

### Examples

The examples below use the JSON text from [Stefan Goessner's JsonPath](http://goessner.net/articles/JsonPath/) (store.json).
Expand Down Expand Up @@ -84,6 +99,7 @@ A list of sample JSON paths and results follows.

JSONPath |Result|Notes
---------|--------------------------------------------------------|------
`$..book.length` |The number of books|`length` is a property of an array
`$.store.book[*].author` |All authors of books in the store
`$..author` |All authors
`$.store.*` |Everything in the store, including books and a bicycle.
Expand All @@ -98,6 +114,5 @@ JSONPath |Result|Notes
`$..book[?(@.isbn)]` |All books that have isbn number
`$..book[?(@.price<10)]` |All books that are cheaper than $10
`$..*` |Everything in the store.
`$..book.length` |The number of books
`$.store.book[ ?((@.author == 'Nigel Rees') || (@.author == 'Evelyn Waugh')) ].title`|The titles of all books by Nigel Rees and Evelyn Waugh

4 changes: 3 additions & 1 deletion test_suite/src/jsonpath_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ BOOST_AUTO_TEST_CASE(test_jsonpath_array_length)
json result = json_query(root,"$..book.length");

std::cout << pretty_print(result) << std::endl;

BOOST_CHECK_EQUAL(1,result.size());
BOOST_CHECK_EQUAL(root["store"]["book"].size(),result[0].as<size_t>());
}


BOOST_AUTO_TEST_CASE(test_jsonpath_book_category)
{
json root = json::parse_string(jsonpath_fixture::book_text());
Expand Down

0 comments on commit ff6c341

Please sign in to comment.