Skip to content

Converting key-values pairs #19655

Discussion options

You must be logged in to vote

@KrishnaJyothika here's a way to this..

Here's a playground link.

Here's the example, somewhat verbose but it does work.

keyValRegex = r'/(?P<key>[^/]+)/(?P<value>[^/]+)'
obj = object(.)

pairs, err = parse_regex_all(obj.resource, keyValRegex)
if err != null {
    abort
}
for_each(pairs) -> | _idx, match | {
    k = to_string(match.key)
    v = to_string(match.value)
    obj, err = set(value: obj, path: [ k ], data: v)
    if err != null {
        abort
    }
}
del(obj.resource)

. = obj

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by pront
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: vrl Anything related to the Vector Remap Language
3 participants