danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
699 stars 158 forks source link

length not working well in jsonpath_examples.cpp #453

Open MonkeybreadSoftware opened 11 months ago

MonkeybreadSoftware commented 11 months ago

The examples does this:

    // The number of books
    json result2 = jsonpath::json_query(booklist, "length($..book)");
    std::cout << "(2) " << result2 << "\n";

output is [1] as length gets passed an array of array and that outer array has value 1. But I think the examples like to output the number of books and not the number of result arrays.

I turned on a bit debugging:

length function arg: [[{"author":"Nigel Rees","category":"reference","price":8.95,"title":"Sayings of the Century"},{"author":"Evelyn Waugh","category":"fiction","price":12.99,"title":"Sword of Honour"},{"author":"Herman Melville","category":"fiction","isbn":"0-553-21311-3","price":8.99,"title":"Moby Dick"},{"author":"J. R. R. Tolkien","category":"fiction","isbn":"0-395-19395-8","price":22.99,"title":"The Lord of the Rings"}]] (2) [1]

So either the example needs a new expression to query length value 4 or the code calling length needs to look into the array first?