Hello,
I am trying to loop through an Array which has key, value pairs that is something like this:
[
{
"Q1": "65a4bea6-ef6e-ea11-a811-000d3aa3ee47"
},
{
"Q5": "5b564b8a-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q11": "c97a7c94-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q12": "33fcc49e-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q13": ""
},
{
"Q14": ""
}
]
However how do i retrieve the value for a specific key say for Q1 or Q2 etc...?
I tried something like this with functions to reflect the function within a compose action: variables('QuestionReferenceArray')[0]['Q1']
variables('QuestionReferenceArray')[int(variables('Question Reference Index'))][outputs('Compose_14')]
This is the error i get:
InvalidTemplate. Unable to process template language expressions in action 'Compose_12' inputs at line '1' and column '23867': 'The template language expression 'variables('QuestionReferenceArray')[int(variables('Question Reference Index'))][outputs('Compose_14')]' cannot be evaluated because property ''Q1'' doesn't exist, available properties are 'Q1'. Please see https://aka.ms/logicexpressions for usage details.'.
Not sure if i am doing this right but would be great if someone could guide me how i could read array data based on a key.
My flow run where the error occurs:
Flow Actions:
Thanks in advance for the help.
Solved! Go to Solution.
Hi @Nithin_Vanam,
The Index in the array is not correct, the index of array starts from 0, the index of the first member should be 0, so you should sub 1 when you input expression, for example:
variables('QuestionReferenceArray')[add(int(variables('Question Reference Index')),-1)][outputs('Compose_14')]
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @Nithin_Vanam
Please elaborate in what you are trying to achieve. From what I can gather would this work:
I took your example from above and added it to a Compose action.
[
{
"Q1": "65a4bea6-ef6e-ea11-a811-000d3aa3ee47"
},
{
"Q5": "5b564b8a-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q11": "c97a7c94-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q12": "33fcc49e-a17c-ea11-a811-000d3aa3ee47"
},
{
"Q13": ""
},
{
"Q14": ""
}
]
Now I added a Parse JSON action, and added the Array as the content.
See below for the Schema I used
Next I added a Apply to each loop and set the input as the Body from the Parse JSON action
This will iterate through each item.
If you want to just get one value, there is no need for the loop as all data can be referenced individually thanks to the Parse JSON action
The schema that was used in the Parse JSON action:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Q1": {
"type": "string"
},
"Q5": {
"type": "string"
},
"Q11": {
"type": "string"
},
"Q12": {
"type": "string"
},
"Q13": {
"type": "string"
},
"Q14": {
"type": "string"
}
},
"required": []
}
}
Proud to be a Flownaut!
Hi @Nithin_Vanam,
The Index in the array is not correct, the index of array starts from 0, the index of the first member should be 0, so you should sub 1 when you input expression, for example:
variables('QuestionReferenceArray')[add(int(variables('Question Reference Index')),-1)][outputs('Compose_14')]
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
DOES JSON scheme have to be the same length as the input? what if sometimes you have less columns of data, youre json schema wont match whats passed into it
Thats fine, as long as they are not set as Required in the schema.
You can technically just use this as your schema, but you wont be able to use dynamic content within your flow.
{}
Proud to be a Flownaut!
User | Count |
---|---|
95 | |
40 | |
25 | |
22 | |
16 |
User | Count |
---|---|
129 | |
51 | |
48 | |
35 | |
24 |