From ff6c341cfceab39ea8b1ec9ad85ce42d9cfe0e4b Mon Sep 17 00:00:00 2001 From: danielaparker Date: Thu, 17 Dec 2015 15:59:25 -0500 Subject: [PATCH] Added test --- doc/jsonpath | 54 ++++++++++++++++++++++++++++--- src/doc/Reference/jsonpath.md | 17 +++++++++- test_suite/src/jsonpath_tests.cpp | 4 ++- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/doc/jsonpath b/doc/jsonpath index 29eab17e35..4bd38eef55 100644 --- a/doc/jsonpath +++ b/doc/jsonpath @@ -527,6 +527,51 @@ basic_json<Char,Alloc> json_query(const basic_json<Char,Alloc>& +

Filter expression

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OperatorDescription
==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 (store.json).

{ "store": {
@@ -586,6 +631,11 @@ std::cout << pretty_print(result) << std::endl;
 
 
 
+$..book.length
+The number of books
+length is a property of an array
+
+
 $.store.book[*].author
 All authors of books in the store
 
@@ -646,10 +696,6 @@ std::cout << pretty_print(result) << std::endl;
 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
diff --git a/src/doc/Reference/jsonpath.md b/src/doc/Reference/jsonpath.md
index 4e7b11523f..e495872e62 100644
--- a/src/doc/Reference/jsonpath.md
+++ b/src/doc/Reference/jsonpath.md
@@ -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).
@@ -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.
@@ -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
 
diff --git a/test_suite/src/jsonpath_tests.cpp b/test_suite/src/jsonpath_tests.cpp
index 8277786566..062d73a7cd 100644
--- a/test_suite/src/jsonpath_tests.cpp
+++ b/test_suite/src/jsonpath_tests.cpp
@@ -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());
 }
  
-
 BOOST_AUTO_TEST_CASE(test_jsonpath_book_category)
 {
     json root = json::parse_string(jsonpath_fixture::book_text());