Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions include/jsoncons_ext/jmespath/jmespath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4431,8 +4431,8 @@ namespace detail {
push_token(token<Json>(begin_multi_select_list_arg), resources, output_stack, ec);
if (JSONCONS_UNLIKELY(ec)) {return jmespath_expression{};}
state_stack.back() = expr_state::multi_select_list;
state_stack.push_back(expr_state::rhs_expression);
state_stack.push_back(expr_state::lhs_expression);
state_stack.push_back(expr_state::rhs_expression);
state_stack.push_back(expr_state::lhs_expression);
context_stack.push_back(expression_context<Json>{});
}
break;
Expand Down Expand Up @@ -4490,7 +4490,8 @@ namespace detail {
case '-':case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
break;
default:
state_stack.back() = expr_state::key_val_expr;
state_stack.back() = expr_state::expect_rbrace;
state_stack.push_back(expr_state::key_val_expr);
break;
}
break;
Expand Down Expand Up @@ -4906,16 +4907,7 @@ namespace detail {
case ',':
push_token(token<Json>(separator_arg), resources, output_stack, ec);
if (JSONCONS_UNLIKELY(ec)) {return jmespath_expression{};}
state_stack.back() = expr_state::key_val_expr;
++p_;
++column_;
break;
case '[':
case '{':
state_stack.push_back(expr_state::lhs_expression);
break;
case '.':
state_stack.push_back(expr_state::sub_expression);
state_stack.push_back(expr_state::key_val_expr);
++p_;
++column_;
break;
Expand All @@ -4942,8 +4934,9 @@ namespace detail {
advance_past_space_character();
break;
case ':':
state_stack.back() = expr_state::expect_rbrace;
state_stack.back() = expr_state::rhs_expression;
state_stack.push_back(expr_state::lhs_expression);
context_stack.push_back(expression_context<Json>{});
++p_;
++column_;
break;
Expand Down
39 changes: 39 additions & 0 deletions test/jmespath/input/test.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
[
{
"given": {
"foo": {
"bar": "baz"
}
},
"cases": [
{
"comment": "Comparator expression evaluates to true boolean",
"expression": "foo.bar == 'baz'",
"result": true
},
{
"comment": "Comparator expression evaluates to false boolean",
"expression": "foo.bar == 'bar'",
"result": false
},
{
"comment": "Multi select list comparator value expression evaluates to true boolean",
"expression": "[foo.bar == 'baz']",
"result": [ true ]
},
{
"comment": "Multi select list comparator value expression evaluates to false boolean",
"expression": "[foo.bar == 'bar']",
"result": [ false ]
},
{
"comment": "Multi select hash comparator value expression evaluates to true boolean",
"expression": "{value: foo.bar == 'baz'}",
"result": { "value": true }
},
{
"comment": "Multi select hash comparator value expression evaluates to false boolean",
"expression": "{value: foo.bar == 'bar'}",
"result": { "value": false }
}
]
}
]

4 changes: 4 additions & 0 deletions test/jmespath/src/jmespath_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ void jmespath_tests(const std::string& fpath)

TEST_CASE("jmespath-tests")
{
SECTION("Tests")
{
jmespath_tests("./jmespath/input/test.json");
}
SECTION("Examples and tutorials")
{
jmespath_tests("./jmespath/input/examples/jmespath-examples.json");
Expand Down
Loading