cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PColley
Regular Visitor

Assign JSON array to gallery not working when assigning a variable

I'm creating the JSON array in a variable and then including that in the response body. (substring is just to strip the final line break and comma, cause that append is in a loop)

 

PColley_0-1661992746357.png

 

If I show that 'galleryItems' variable (including the substring) in a label, then copy and paste the data into the array as raw data - the gallery populates as expected.

 

PColley_1-1661992896590.pngPColley_2-1661992965874.png

 

However, when I assign the exact same var to be the array in the JSON the gallery table shows as empty. Any ideas about what I'm missing?

 

With raw data:

PColley_3-1661993150868.png

 

With the variable:

PColley_4-1661993227767.png

 

Edit. just in case it helps this is the schema for the response action:

{
    "type": "object",
    "properties": {
        "json": {
            "type": "string"
        },
        "responseCode": {
            "type": "string"
        },
        "galleryItems": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "fileName": {
                        "type": "string"
                    },
                    "fileUrl": {
                        "type": "string"
                    }
                },
                "required": [
                    "fileName",
                    "fileUrl"
                ]
            }
        }
    }
}
1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User
Dual Super User

Remove the comma from the end of the object in the Append to array statement and then skip using the substring.  Append to Array will automatically supply the commas between the objects you are appending so you don't need to supply them and then don't need to strip the last one off.  Make sure the variable type is actually array and that you are using the append to array action, not append to string.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

Remove the comma from the end of the object in the Append to array statement and then skip using the substring.  Append to Array will automatically supply the commas between the objects you are appending so you don't need to supply them and then don't need to strip the last one off.  Make sure the variable type is actually array and that you are using the append to array action, not append to string.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thanks so much Paul, only other thing was I had to remove the square brackets from my response body now that I've updated that variable to be an array as they're already included.

 

Everything you suggested makes perfect sense I was just burned out on debugging I suppose and a little green to Power Apps. Really appreciate your response and all your other responses to questions I have used along the way.

Sorry I missed the square brackets.  Yes you would need to remove that also.  You were treating the JSON array as though it were string data, but if you use an array variable its already in JSON array format internally so no string manipulation is needed.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,807)