Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

How to parse JSON properly?

Posted on 26 Nov 2024 10:13:08 by 12
Hello together, 
 
I am currently working on a PowerAPP that requries Parsing of JSON-Arrays. This is way harder than I thought. Maybe I do something wrong and you could give me a pointer in the right direction. 
 
Lets talk about the Situation: 
I have a SharePoint List with only one Column. That Columns contains the JSON-Array which is needed to be parsed. The important point is now that I need to read back the JSON-String into an Table. Because I want to display the results in a gallery. 
 
Title Result
Currently not used but later for Filtering JSON-Array
 
Each Line contains one JSON-Array with the same structure but individual Data: 
{
    "Data": [
        {
            "Choices": "YES;NO;MAYBE",
            "ColumnType": "Form 1",
            "Data": "YES",
            "FormName": "Form 1",
            "QuestionNR": 1,
            "Requried": "Yes",
            "Title": "Would you recommend this Pizza?"
        },
        {
            "Choices": "YES;NO;MAYBE",
            "ColumnType": "Choices",
            "Data": "MAYBE",
            "FormName": "Form 1",
            "QuestionNR": 3,
            "Requried": "Yes",
            "Title": "Would you recommend this Pizza?"
        }
    ]
}
 
Now the Idea is to read back the Information into a Collection / Table to display the Data in a Gallery. Each Entry in the Sharepoint-List where the JSON-Array is stored should be one Entry in the Gallery. 
 
Summary:
  • Reading JSON String
  • Parsing JSON 
  • Create Table based on Parsed JSON
Would be great if you can support me here. I tried several ways but for me its not possible to get the Data back. 
  • Suggested answer
    DBO_DV Profile Picture
    DBO_DV 4,158 on 26 Nov 2024 at 13:42:11
    How to parse JSON properly?
    If you want to have everything at once you could out it in the OnStart property off the app. 
    This will make the loading time a bit longer
     
    Clear(colNewTable);
    ForAll(Datasource As X,
      Collect(colNewTable, 
        ForAll(Table(ParseJSON(X.Result).Data),
          {
            Choices: Split(Text(Value.Choices),","),
            ColumnType: Text(Value.ColumnType),
            Data: Text(Value.Data),
            FormName: Text(Value.FormName),
            QuestionNR: Value(Value.QuestionNR),
            Requried: Text(Value.Requried),
            Title: Text(Value.Title),
            FilterID: X.Title
          }
        )
      )
    )
    If this solvede your porblem please accept it as solution so others can find it as well. 
    If it helped in any other way consider liking it so we can keep supporting eachother. 
  • PowerAppBuilder24 Profile Picture
    PowerAppBuilder24 12 on 26 Nov 2024 at 13:10:07
    How to parse JSON properly?
    Hey @DBO_DV
     
    currently the Data is loaded in the Gallery if Screen is visible (default PowerAPPs behaviour). The problem is if I dont use a gallery I am not able to use the elegant Way of ThisItem.XYZ. 
     
    If I remember correctly - I tried that with another forall-Loop. Do you have an good Way of doing that? 
     
    As far as I know it should look like this: 
    ForAll Sharepoint-Lists entries: 
        ForAll JSON-Array Elements:
           ParseJSON()...
     
    Maybe you could give me some hints - I highly appreciate it! 
     
  • Suggested answer
    DBO_DV Profile Picture
    DBO_DV 4,158 on 26 Nov 2024 at 12:43:41
    How to parse JSON properly?
     
    When do you load the data into your app? Directly on start?
    you could put this onStart of the app or when you Navigate to this screen. 
     
    If this solvede your porblem please accept it as solution so others can find it as well. 
    If it helped in any other way consider liking it so we can keep supporting eachother.  
  • PowerAppBuilder24 Profile Picture
    PowerAppBuilder24 12 on 26 Nov 2024 at 12:32:26
    How to parse JSON properly?
    Hey @DBO_DV
     
    thank you for the Link. The Problem is that I dont wanna click on a extra button. The Gallery should be able to display some Info directly - without pressing the "View" icon... 
     
    The Link works but it assumes that you need to click on the button. I need that without the click.. Do you know a good way to achieve this? 
     
    Best regards 
  • Suggested answer
    DBO_DV Profile Picture
    DBO_DV 4,158 on 26 Nov 2024 at 10:33:38
    How to parse JSON properly?
     
     
    There it is explained pretty easily. 
     
    If this solvede your porblem please accept it as solution so others can find it as well. 
    If it helped in any other way consider liking it so we can keep supporting eachother. 

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,129

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,797

Leaderboard