-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Labels
Description
Component(s)
pkg/ottl
Is your feature request related to a problem? Please describe.
The current implementation of SliceToMap has a required argument, keyPath, which expects an array of keys from the input slice of objects. These objects need to have a same key. The values corresponding to these keys must be strings.
This restriction limits the use cases of this function. The given slice of objects might not always have an entry with the same key.
Describe the solution you'd like
Mark keyPath Optional. If keyPath isn't specified, use the string representation of the index when looping through objects in the slice.
i.e:
type SliceToMapArguments[K any] struct {
Target ottl.Getter[K]
KeyPath ottl.Optional[[]string]
ValuePath ottl.Optional[[]string]
}
m1 := {
"data1": "param1"
"data2": "param2"
}
m2 := {
"data3": "param3"
"data4": "param4"
}
Target := []any {m1, m2}
SliceToMap(Target) -> {
"0": {
"data1": "param1"
"data2": "param2"
}
"1": {
"data3": "param3"
"data4": "param4"
}
}
Describe alternatives you've considered
N/A
Additional context
N/A
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Reactions are currently unavailable