Skip to content

Commit

Permalink
to_jsonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 14, 2023
1 parent 413ceb9 commit af92dc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/jsoncons_ext/jsonpath/path_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,20 @@ namespace jsonpath {
std::basic_string<CharT, std::char_traits<CharT>, Allocator> buffer(alloc);

buffer.push_back('$');
for (auto element : location)
for (const auto& element : location)
{
switch (element->element_kind())
switch (element.element_kind())
{
case path_node_kind::name:
case path_element_kind::name:
buffer.push_back('[');
buffer.push_back('\'');
jsoncons::jsonpath::escape_string(element->name().data(), element->name().size(), buffer);
jsoncons::jsonpath::escape_string(element.name().data(), element.name().size(), buffer);
buffer.push_back('\'');
buffer.push_back(']');
break;
case path_node_kind::index:
case path_element_kind::index:
buffer.push_back('[');
jsoncons::detail::from_integer(element->index(), buffer);
jsoncons::detail::from_integer(element.index(), buffer);
buffer.push_back(']');
break;
}
Expand Down
3 changes: 3 additions & 0 deletions test/jsonpath/src/path_node_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ TEST_CASE("test to_json_location")
location /= "bar";
location /= 7;

std::string jsonpath_string = "$['foo']['bar'][7]";

CHECK((jsonpath::to_json_location(a4) == location));
CHECK((jsonpath::to_jsonpath(location) == jsonpath_string));
}
}

0 comments on commit af92dc9

Please sign in to comment.