mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
rename at_path_new to at_path_with_wildcard
This commit is contained in:
@@ -39,26 +39,28 @@ int main(void) {
|
||||
// std::cout << tweets["search_metadata"]["count"] << " results." <<
|
||||
// std::endl;
|
||||
|
||||
|
||||
|
||||
simdjson::dom::element parsed_json = parser.parse(json_string);
|
||||
// std::cout << parsed_json["firstName"] << std::endl;
|
||||
|
||||
// selects all the top level elements
|
||||
// auto result = parsed_json.at_path_new("$.*");
|
||||
auto result = parsed_json.at_path_with_wildcard("$.*");
|
||||
|
||||
// selects all the top level elements
|
||||
// auto result = parsed_json.at_path_new("$[*]");
|
||||
// auto result = parsed_json.at_path_with_wildcard("$[*]");
|
||||
|
||||
// selects all address properties - $.address.*
|
||||
// auto result = parsed_json.at_path_new("$.address.*");
|
||||
// auto result = parsed_json.at_path_with_wildcard("$.address.*");
|
||||
|
||||
// selects all address properties - $["address"].*
|
||||
// auto result = parsed_json.at_path_new("$['address'].*");
|
||||
// auto result = parsed_json.at_path_with_wildcard("$['address'].*");
|
||||
|
||||
// selects all phoneNumbers properties - $.phoneNumbers.*
|
||||
// auto result = parsed_json.at_path_new("$.phoneNumbers.*");
|
||||
// auto result = parsed_json.at_path_with_wildcard("$.phoneNumbers.*");
|
||||
|
||||
// selects nested properties - $.*.streetAddress
|
||||
auto result = parsed_json.at_path_new("$.*.streetAddress");
|
||||
// auto result = parsed_json.at_path_with_wildcard("$.*.streetAddress");
|
||||
|
||||
std::vector<simdjson::dom::element> values = result.value();
|
||||
|
||||
|
||||
@@ -70,12 +70,12 @@ inline simdjson_result<dom::element> simdjson_result<dom::array>::at_path(
|
||||
}
|
||||
|
||||
inline simdjson_result<std::vector<dom::element>>
|
||||
simdjson_result<dom::array>::at_path_new(
|
||||
simdjson_result<dom::array>::at_path_with_wildcard(
|
||||
std::string_view json_path) const noexcept {
|
||||
if (error()) {
|
||||
return error();
|
||||
}
|
||||
return first.at_path_new(json_path);
|
||||
return first.at_path_with_wildcard(json_path);
|
||||
}
|
||||
|
||||
inline simdjson_result<dom::element>
|
||||
@@ -169,7 +169,7 @@ array::at_pointer(std::string_view json_pointer) const noexcept {
|
||||
}
|
||||
|
||||
inline simdjson_result<std::vector<element>>
|
||||
array::at_path_new(std::string_view json_path) const noexcept {
|
||||
array::at_path_with_wildcard(std::string_view json_path) const noexcept {
|
||||
if (json_path.length() == 3 && json_path[0] == '$' && json_path[1] == '.' &&
|
||||
json_path[2] == '*') {
|
||||
return get_values();
|
||||
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
* - INVALID_JSON_POINTER if the JSON pointer is invalid and cannot be parsed
|
||||
*/
|
||||
inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
|
||||
inline simdjson_result<std::vector<element>> at_path_new(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<std::vector<element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
|
||||
/**
|
||||
* Get the value associated with the given JSONPath expression. We only support
|
||||
* JSONPath queries that trivially convertible to JSON Pointer queries: key
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
simdjson_inline simdjson_result(error_code error) noexcept; ///< @private
|
||||
|
||||
inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> at_path_new(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<dom::element> at(size_t index) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> get_values() const noexcept;
|
||||
|
||||
@@ -129,9 +129,9 @@ simdjson_inline simdjson_result<dom::element> simdjson_result<dom::element>::at_
|
||||
return at_pointer(json_pointer);
|
||||
}
|
||||
|
||||
simdjson_inline simdjson_result<std::vector<dom::element>> simdjson_result<dom::element>::at_path_new(const std::string_view json_path) const noexcept {
|
||||
simdjson_inline simdjson_result<std::vector<dom::element>> simdjson_result<dom::element>::at_path_with_wildcard(const std::string_view json_path) const noexcept {
|
||||
if (error()) { return error(); }
|
||||
return first.at_path_new(json_path);
|
||||
return first.at_path_with_wildcard(json_path);
|
||||
}
|
||||
|
||||
#ifndef SIMDJSON_DISABLE_DEPRECATED_API
|
||||
@@ -425,14 +425,14 @@ inline simdjson_result<element> element::at_pointer(std::string_view json_pointe
|
||||
}
|
||||
}
|
||||
|
||||
inline simdjson_result<std::vector<element>> element::at_path_new(std::string_view json_path) const noexcept {
|
||||
inline simdjson_result<std::vector<element>> element::at_path_with_wildcard(std::string_view json_path) const noexcept {
|
||||
SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
|
||||
|
||||
switch (tape.tape_ref_type()) {
|
||||
case internal::tape_type::START_OBJECT:
|
||||
return object(tape).at_path_new(json_path);
|
||||
return object(tape).at_path_with_wildcard(json_path);
|
||||
case internal::tape_type::START_ARRAY:
|
||||
return array(tape).at_path_new(json_path);
|
||||
return array(tape).at_path_with_wildcard(json_path);
|
||||
default: {
|
||||
return std::vector<element>{};
|
||||
// if (!json_path.empty()) { // a non-empty string can be invalid, or accessing a primitive (issue 2154)
|
||||
|
||||
@@ -401,7 +401,7 @@ public:
|
||||
*/
|
||||
inline simdjson_result<element> at_pointer(const std::string_view json_pointer) const noexcept;
|
||||
|
||||
inline simdjson_result<std::vector<element>> at_path_new(const std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<std::vector<element>> at_path_with_wildcard(const std::string_view json_path) const noexcept;
|
||||
|
||||
/**
|
||||
* Get the value associated with the given JSONPath expression. We only support
|
||||
@@ -548,7 +548,7 @@ public:
|
||||
simdjson_inline simdjson_result<dom::element> operator[](const char *key) const noexcept;
|
||||
simdjson_result<dom::element> operator[](int) const noexcept = delete;
|
||||
simdjson_inline simdjson_result<dom::element> at_pointer(const std::string_view json_pointer) const noexcept;
|
||||
simdjson_inline simdjson_result<std::vector<dom::element>> at_path_new(const std::string_view json_path) const noexcept;
|
||||
simdjson_inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(const std::string_view json_path) const noexcept;
|
||||
simdjson_inline simdjson_result<dom::element> at_path(const std::string_view json_path) const noexcept;
|
||||
[[deprecated("For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
|
||||
simdjson_inline simdjson_result<dom::element> at(const std::string_view json_pointer) const noexcept;
|
||||
|
||||
@@ -48,12 +48,12 @@ inline simdjson_result<dom::element> simdjson_result<dom::object>::at_pointer(
|
||||
return first.at_pointer(json_pointer);
|
||||
}
|
||||
inline simdjson_result<std::vector<dom::element>>
|
||||
simdjson_result<dom::object>::at_path_new(
|
||||
simdjson_result<dom::object>::at_path_with_wildcard(
|
||||
std::string_view json_path) const noexcept {
|
||||
if (error()) {
|
||||
return error();
|
||||
}
|
||||
return first.at_path_new(json_path);
|
||||
return first.at_path_with_wildcard(json_path);
|
||||
}
|
||||
inline simdjson_result<dom::element> simdjson_result<dom::object>::at_path(
|
||||
std::string_view json_path) const noexcept {
|
||||
@@ -193,7 +193,7 @@ object::at_pointer(std::string_view json_pointer) const noexcept {
|
||||
return child;
|
||||
}
|
||||
inline simdjson_result<std::vector<element>>
|
||||
object::at_path_new(std::string_view json_path) const noexcept {
|
||||
object::at_path_with_wildcard(std::string_view json_path) const noexcept {
|
||||
SIMDJSON_DEVELOPMENT_ASSERT(
|
||||
tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
|
||||
if (json_path
|
||||
@@ -255,7 +255,7 @@ object::at_path_new(std::string_view json_path) const noexcept {
|
||||
|
||||
for (; iterator != child_value.end(); ++iterator) {
|
||||
auto child_result =
|
||||
iterator->at_path_new("$" + std::string(json_path)).value();
|
||||
iterator->at_path_with_wildcard("$" + std::string(json_path)).value();
|
||||
result.insert(result.end(), child_result.begin(),
|
||||
child_result.end());
|
||||
}
|
||||
@@ -282,7 +282,7 @@ object::at_path_new(std::string_view json_path) const noexcept {
|
||||
|
||||
for (; iterator != child_value.end(); ++iterator) {
|
||||
auto child_result =
|
||||
iterator->at_path_new("$" + std::string(json_path)).value();
|
||||
iterator->at_path_with_wildcard("$" + std::string(json_path)).value();
|
||||
result.insert(result.end(), child_result.begin(),
|
||||
child_result.end());
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public:
|
||||
*/
|
||||
inline simdjson_result<element> at_pointer(std::string_view json_pointer) const noexcept;
|
||||
|
||||
inline simdjson_result<std::vector<element>> at_path_new(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<std::vector<element>> at_path_with_wildcard(std::string_view json_path) const noexcept;
|
||||
|
||||
/**
|
||||
* Get the value associated with the given JSONPath expression. We only support
|
||||
@@ -267,7 +267,7 @@ public:
|
||||
inline simdjson_result<dom::element> operator[](const char *key) const noexcept;
|
||||
simdjson_result<dom::element> operator[](int) const noexcept = delete;
|
||||
inline simdjson_result<dom::element> at_pointer(std::string_view json_pointer) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> at_path_new(std::string_view json_path_new) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> at_path_with_wildcard(std::string_view json_path_new) const noexcept;
|
||||
inline simdjson_result<dom::element> at_path(std::string_view json_path) const noexcept;
|
||||
inline simdjson_result<dom::element> at_key(std::string_view key) const noexcept;
|
||||
inline simdjson_result<std::vector<dom::element>> get_values() const noexcept;
|
||||
|
||||
Reference in New Issue
Block a user