web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to get an array st...
Power Apps
Unanswered

How to get an array stored in a string into a collection

(0) ShareShare
ReportReport
Posted on by 406

I have a structured set of data held as a string in a variable in this format:

 

{field1: 123, field2: "ABC"},{field1:345, field2: "DEF"}

 

I am trying to get this data into a collection. It works fine if I paste the string into the statement:

 

ClearCollect(colTest, {field1:123, field2:"ABC"},{field1:456, field2: "DEF"})

 

but does not work if I use a variable to pass the data:

 

Set(gblTest, [{field1:123, field2:"ABC"},{field1:456, field2: "DEF"}]);
ClearCollect(colTest, gblTest)

 

Am I missing something simple here?

 

Thanks.

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @biterbit ,

    You need to "drill down" as you have Value as the top table

    Set(
     gblTest,
     [
     {
     field1: 123,
     field2: "ABC"
     },
     {
     field1: 345,
     field2: "DEF"
     }
     ]
    );
    ClearCollect(
     colTable,
     ForAll(
     gblTest,
     {
     Field_1: Value.field1,
     Field_2: Value.field2
     }
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

     

  • biterbit Profile Picture
    406 on at

    Hi @WarrenBelz. That was very useful and put me on the right track. I don't quite understand why the data is placed within the Value column - does that always happen when you populate a collection from a table of values? Also, is there any way to use the fieldname values from the original data rather than hard-coding them into the ForAll loop?

     

    Many thanks

  • biterbit Profile Picture
    406 on at

    @WarrenBelz : I've just realised that this still leaves me with the problem that, although this works when I directly set the gblTest variable (as in your example above), it does not work when that same data is in a string variable. I guess I have to convert a string that contains this:

    [{field1:123, field2:"ABC"},{field1:456, field2: "DEF"}]

    into a table? Is that right? 

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @biterbit ,

    Sort of two questions in one - firstly why not simply collect in the first place

    ClearCollect(
     colTable,
     {
     field1: 123,
     field2: "ABC"
     },
     {
     field1: 345,
     field2: "DEF"
     }
    )

    and you will get the structure you want. Your code will automatically create the Value parent table in the Variable.
    I must admit I never use Variables to store Tables - that is what collections are for (they are actually Table Variables), but a with bit of experimenting, you can do this.

    Set(
     gblTest,
     [
     {
     field1: 123,
     field2: "ABC"
     },
     {
     field1: 345,
     field2: "DEF"
     }
     ]
    );
    ClearCollect(
     colTable,
     ForAll(
     gblTest,
     Value
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • biterbit Profile Picture
    406 on at

    @WarrenBelz The data I am using is coming into PowerApps from an external source. I can format the input as I want, but it will always come as a string. So the challenge is to get that string into a table/collection structure. The string looks like it is in the same format as you would use to create a collection in PowerApps, but it does not accept that input as a string variable.

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    @biterbit ,

    What is the exact format of the data coming in (in Text please)

  • biterbit Profile Picture
    406 on at

    @WarrenBelz : its currently coming in like this:

    [{"field1":"123", "field2":"ABC"},{"field1":456, "field2": "DEF"}]

    but I've tried a number of alternative formats like:

    [{'field1':"123", 'field2':"ABC"},{'field1':456, 'field2': "DEF"}]
    {'field1':"123", 'field2':"ABC"},{'field1':456, 'field2': "DEF"}

    I can get the individual records into a collection using a Split command but I can't get the individual fields recognised as anything but a single string.

     

    Thanks for your help so far.

  • WarrenBelz Profile Picture
    153,026 Most Valuable Professional on at

    Hi @biterbit ,

    I will raise the white flag here too - I did some testing and cannot use [ ] or { } dynamically from Text.

  • biterbit Profile Picture
    406 on at

    @WarrenBelz : Yes - looks like a built-in limitation. Thanks for your support in confirming that it's not just me.

  • FeierCiprian Profile Picture
    20 on at

    Set your response from Power Automate as STRING (using expressions)
    then in Power Apps you will receive the string of data and you can transform it and store data into collection with the help of this video.

    Send Array/JSON Response from Power Automate Flow to Power Apps 

     

    Hope it helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard