cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Swap keys and values

shreegeet
New Contributor II

Hi,

I have a use case of lookup function where I have to use the same expression library but the lookup will happen both on the basis of key and value pair.
Below is the expression library that I have uploaded
{
โ€œLookupโ€: {
โ€œKey1โ€: โ€œValue1โ€,
โ€œKey2โ€: โ€œValue2โ€,
โ€œKey3โ€: โ€œValue3โ€,
โ€œKey4โ€:โ€œValue4โ€
}
}
Now I will get value1 from previous snaps, I want to use value1 to retrieve data as Key1.

Can you suggest how this can be achieved?

Regards,
Shreegeet

2 REPLIES 2

bojanvelevski
Valued Contributor

If i understood correctly, you want to get a value from the config file, based on an incoming field in the pipeline. If thatโ€™s correct, try this:

lib.config.Lookup.get($field)

Where โ€œconfigโ€ is the name of the ecpression library, and โ€œ$fieldโ€ is the incoming field (value1 in your original post).

Bojan

SpiroTaleski
Valued Contributor

@shreegeet

If you want to use the incoming value(from previous snaps) in order to retrieve the object key, then you can use the following expession:

lib.config.Lookup.keys().find(k=>lib.config.Lookup[k]==$incoming_value)

BR,
Spiro Taleski