{ 'a': true, 'b': true, 'c': false, 'd': false }
The code above should dynamically be converted to
{ { 'a': true }, { 'b': true }, { 'c': false }, { 'd': false } }
is that possible? Thanks in advance
Discussion posts and replies are publicly visible
What's your use case?
Depending on the particulars, I expect you could probably utilize a!keys() to get the keys from the original dictionary, then iterate over that list, creating a set of new dictionaries each containing just one property from the original.
Could you please give me an example how can I create a set of new dictionaries? I am trying with a!forEach
I guess it takes a little trickery to get the plaintext key name to be the key in a new dictionary, but if we (for instance) use JSON as an intermediary step, that'll pretty much do it for us...
a!localVariables( local!originalDictionary: { 'a': true, 'b': true, 'c': false, 'd': false }, local!keys: a!keys(local!originalDictionary), a!forEach( local!keys, /* note: double quotes have to be handled carefully here */ a!fromJson( "{""" & fv!item & """:" & property(local!originalDictionary, fv!item) & "}" ) ) )
Oh, I just remembered there's a cleaner way to do this using a!update() (which can inject a new property into an existing dictionary or map), so no need to manually construct a JSON string to back-convert. See below:
a!localVariables( local!originalDictionary: { 'a': true, 'b': true, 'c': false, 'd': false }, local!keys: a!keys(local!originalDictionary), a!forEach( local!keys, a!update( data: a!map(), index: fv!item, value: property(local!originalDictionary, fv!item) ) ) )
Wow! That is it, it definitely works like a charm. Many thanks!