Skip to content

length not working well in jsonpath_examples.cpp #453

@MonkeybreadSoftware

Description

@MonkeybreadSoftware

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions