Inverse of items() ? #6548
-
|
At the moment, if you want to convert an object into an array, its possible via var exampleObj = {
a: 1,
b: 2
}
var asArray = items(exampleObject)
/*
[
{
key: 'a'
value: 1
}
{
key: 'b'
value: 2
}
]
*/however, is it possible to iterate through an array to construct an object? Something like var modifiedObject = [for kvp in items(exampleObj): {
'${kvp.key}': '${kvp.value} but modified'
}]
/*
desired:
{
a: '1 but modified'
b: '2 but modified'
}
actual:
[
{
a: '1 but modified'
}
{
b: '2 but modified'
}
]
*/ |
Beta Was this translation helpful? Give feedback.
Answered by
brwilkinson
Apr 15, 2022
Replies: 1 comment 2 replies
-
|
I won't comment too much, other than to say, it's not natively supported. I saw this idea posted not too long ago... I am not aware of any open issues for it this, I am guessing we may have one.
main.bicepparam input array = [
{
key: 'k1'
value: {
prop1: 'value1'
}
}
{
key: 'k2'
value: {
prop1: 'value2'
}
}
]
module loop './nested_loop.bicep' = [for (item, i) in input: {
name: 'loop${i}'
params: {
input: item
index: i
}
}]
output finalDictionary object = reference(resourceId('Microsoft.Resources/deployments', 'loop${(length(input) - 1)}')).outputs.dictionary.valuenested_loop.bicepparam input object
param index int
var dictionaryItem = {
'${input.key}': {
value: input.value
}
}
output dictionary object = ((index == 0) ? dictionaryItem : union(reference(resourceId('Microsoft.Resources/deployments', 'loop${(index - 1)}'), '2021-04-01').outputs.dictionary.value, dictionaryItem)) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
brwilkinson
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I won't comment too much, other than to say, it's not natively supported.
I saw this idea posted not too long ago...
I am not aware of any open issues for it this, I am guessing we may have one.
main.bicep
nest…