You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My suggestion would be to enable the support to array, at least for a specific position in array, we don't need to iterate over all array, just get an index and match the value. I implemented that solution locally and worked perfectly, so here is my idea:
absl::StatusOr<Json::ObjectSharedPtr> next_node_result;
const std::string keyword_array = "@array_";
const std::int16_t keyword_array_sizeof = 7;
for (unsignedlong i = 0; i < keys.size() - 1; i++) {
if (keys[i].find(keyword_array) != std::string::nops){
next_node_result = node->getObjectArray(keys[i].substr(keyword_array_sizeof))[0];
}else{
next_node_result = node->getObject(keys[i]);
}
}
A bit explanation about my idea. If the selector has @array_ it means we want to use array and not just simple object. In that case we use the getObjectArray and not getObject. Now the selector would be data.@array_regions.
In this sample code I'm getting always the first item of array (index zero), but we should add it to selector as well, like this one: data.@array_3_regions, so we can pick up the correct item.
For me lookup through an array is very important and a requirement, so we can't use this filter without this. I have the code ready to open a PR but would like to hear you guys first and I can push my PR.
The text was updated successfully, but these errors were encountered:
Title: Improvement to accept array match on Json-To-Metadata filter
Description:
I'm using the Json-To-Metadata filter and it works very well for JSON fields outside arrays. But Imagine the following structure:
How can I match using
data.regions[0]
where value equal toamerica
? Simple answer. I can't. Because the current filter is usingnode->getObject()
(https://github.com/envoyproxy/envoy/blob/main/source/extensions/filters/http/json_to_metadata/filter.cc#L370), it never expects an array.My suggestion would be to enable the support to array, at least for a specific position in array, we don't need to iterate over all array, just get an index and match the value. I implemented that solution locally and worked perfectly, so here is my idea:
A bit explanation about my idea. If the selector has
@array_
it means we want to use array and not just simple object. In that case we use thegetObjectArray
and notgetObject
. Now the selector would bedata.@array_regions
.In this sample code I'm getting always the first item of array (index zero), but we should add it to selector as well, like this one:
data.@array_3_regions
, so we can pick up the correct item.For me lookup through an array is very important and a requirement, so we can't use this filter without this. I have the code ready to open a PR but would like to hear you guys first and I can push my PR.
The text was updated successfully, but these errors were encountered: