Hello,
I need your help in finding the best solution for this situation:
I have and object with some attributes that could contain one ore more values. These attribute names differ with only one letter (in fact is a number) for example: A1, A2, A3.
Let's assume the object will look like this:
{
"ObjectTitle":"Some Title",
"A1":[
{
"Item":"A1I1",
"Value":"A1V1"
},
{
"Item":"A1I2",
"Value":"A1V2"
}
],
"A2":[
{
"Item":"A2I1",
"Value":"A2V1"
}
],
"A3":[
{
"Item":"A3I1",
"Value":"A3V1"
},
{
"Item":"A3I2",
"Value":"A3V2"
}
]
}
Now I need to collect the values of these attributes in their respective array variables arrA1, arrA2, arrA3.
I have managed to to this for one of the arrays:
Where "Apply to each" condition is: variables('objContract')?['A1']
and "Append to array variable" value is: item()?['Value']
Now, my problem is that I have to do this for about 10 attributes.
So the question is: there is a way not to repeat the "Apply to each" for every array variable but to create a bigger "Apply to each" (for an numeric array [1,2,3]) and use some dynamic variable names to populate content for all arrays? (because all depends on a single letter)
Kind Regards,
Lucian
Hi @Chriddle ,
Thank you for your response. I did not have the chance to test in into "production" but from the test following your instruction it seems that it would be exactly what I need.
So thank you very much for your time.🙏
Kind Regards,
Lucian
Not sure if I've gotten that 😉
The result should be something like this?
[
{
"Name": "A1",
"Values": [
"A1V1",
"A1V2"
]
},
{
"Name": "A2",
"Values": [
"A2V1"
]
},
{
"Name": "A3",
"Values": [
"A3V1",
"A3V2"
]
}
]
Then you first need a Select to get the property names and a second Select to get the values for each of these names:
Select
From:
skip(
xpath(
xml(
json(
concat(
'{"root":',
outputs('Data'),
'}'
)
)
),
'/root/*'
),
1
)
Map:
xpath(xml(item()),'name(/*)')
Select 2
From:
union(body('Select'), json('[]'))
Map Name:
item()
Map Values:
xpath(
xml(
json(
concat(
'{"root":',
outputs('Data'),
'}'
)
)
),
concat('/root/',item(),'/Value/text()')
)
Hi @Chriddle ,
Thank you for your response that is very usefull for another project where I need to collect all of the attribute values into a single array.
But this time what I would like to achieve without repeating steps (if possile) to create three arrays with the "corresponding" values.
For example, the expeced result would be:
A1Array shoud contain the values for A1 property:
A1V1
A1V2
A2Array shoud contain the values for A2 property:
A2V1
A3Array shoud contain the values for A3 property:
A3V1
A3V2
Kind of create "n" tables/arrays (in the example above 3) with their corresponding values.
Or, completing your idea - like distributing the AnVx values to the corresponding AnArray variable without creating n "Apply to each" loops.
Kind Regards,
Lucian
Try xPath:
Select:
From:
skip(
xpath(
xml(
json(
concat(
'{"root":',
outputs('Data'),
'}'
)
)
),
'/root/*'
),
1
)
Map Item:
first(xpath(item(), '//Item/text()'))
Map Value:
first(xpath(item(), '//Value/text()'))
returns
Tomac
986
Moderator
stampcoin
699
Super User 2025 Season 2
Riyaz_riz11
577
Super User 2025 Season 2