diff --git a/examples/quickstart/quickstart.cpp b/examples/quickstart/quickstart.cpp index 8185389fa..853fa2959 100644 --- a/examples/quickstart/quickstart.cpp +++ b/examples/quickstart/quickstart.cpp @@ -85,6 +85,15 @@ void wildcard_bracket_element_properties_address() { print_result(values); } +void wildcard_bracket_element_properties_address_bracket() { + // selects all address properties - $["address"].* + std::cout << "Result for $['address'][*]" << "\n"; + auto result = parsed_json.at_path_with_wildcard("$['address'][*]"); + + std::vector values = result.value(); + print_result(values); +} + void wildcard_dot_element_properties_phoneNumbers() { // selects all phoneNumbers properties - $.phoneNumbers.* std::cout << "Result for $.phoneNumbers.*" << "\n"; @@ -108,8 +117,8 @@ int main(int argc, char **argv) { wildcard_bracket_top_level_elements(); wildcard_dot_element_properties_address(); wildcard_bracket_element_properties_address(); + wildcard_bracket_element_properties_address_bracket(); wildcard_dot_element_properties_phoneNumbers(); wildcard_bracket_element_nested_properties_streetAddress(); - return 0; } diff --git a/examples/quickstart/quickstart_benchmark.cpp b/examples/quickstart/quickstart_benchmark.cpp index f4949aea6..bd4fbb059 100644 --- a/examples/quickstart/quickstart_benchmark.cpp +++ b/examples/quickstart/quickstart_benchmark.cpp @@ -115,6 +115,26 @@ void BM_wildcard_bracket_element_properties_address(benchmark::State &state) { BENCHMARK(BM_wildcard_bracket_element_properties_address)->UseManualTime(); +void BM_wildcard_bracket_element_properties_address_bracket(benchmark::State &state) { + for (auto _ : state) { + auto start = std::chrono::high_resolution_clock::now(); + + // selects all address properties - $["address"][*] + auto result = parsed_json.at_path_with_wildcard("$['address'][*]"); + + std::vector values = result.value(); + + auto end = std::chrono::high_resolution_clock::now(); + + auto elapsed_seconds = + std::chrono::duration_cast>(end - start); + + state.SetIterationTime(elapsed_seconds.count()); + } +} + +BENCHMARK(BM_wildcard_bracket_element_properties_address_bracket)->UseManualTime(); + void BM_wildcard_dot_element_properties_phoneNumbers(benchmark::State &state) { for (auto _ : state) { auto start = std::chrono::high_resolution_clock::now(); diff --git a/include/simdjson/dom/object-inl.h b/include/simdjson/dom/object-inl.h index dbfac462c..6dd64afce 100644 --- a/include/simdjson/dom/object-inl.h +++ b/include/simdjson/dom/object-inl.h @@ -269,6 +269,10 @@ object::at_path_with_wildcard(std::string_view json_path) const noexcept { key += json_path[i]; ++i; } + } else if (json_path[i] == '[' && json_path[i + 1] == '*' && + json_path[i + 2] == ']') { + key += json_path[i + 1]; + i += 2; } std::vector child_values;