How can we parse and retrieve nested json data in canvas app using collection

Shweta Rajguru 0 Reputation points
2025-07-31T06:24:34.69+00:00

I have a record in varAuditResult has this structure:

  1. {"AuditID": "4dsd555sde-a8956-2333-0008-354867sdcsdc8", "CreatedOn": "2020-05-20T21:33:35Z", "changeData": "{"changedAttributes":[{"logicalName":"isdisabled","oldValue":"False","newValue":"True"}]}" }
  2. { "AuditID": "4dsd555sde-a8956-2333-0008-354867sdcsdc8", "CreatedOn": "2020-05-20T21:33:35Z", "changeData": "05/20/2025 18:15:21,4" }

this kind of data as a output so i want show AuditID , Created On , logical name, OldValue, newValue in text label in gallery i am putting formulas on OnVisible of screen

It get difficult to retrieve and i have two types of data in changeData which above i shared is string data and second one record is type of integer so before retriving the logicalName , Oldvalue, NewValue i want check if there string or integer after that whatever output shown in the changedata i want parse that output and add into collection like im doing in below formulas

Set(
    varAuditResult,
    GetAuditHistory.Run()
);
ClearCollect(
    colAuditData,
    ForAll(
        Table(ParseJSON(varAuditResult.auditdata)),
        {
            AuditID: Text(Value.AuditID),
            CreatedOn: Text(Value.CreatedOn),
            changedData:If(
            StartsWith(varAuditResult.changedattribute, "{") || StartsWith(varAuditResult.changedattribute, "["),
            // Handle JSON with changedAttributes
            ForAll(
                Table(ParseJSON(varAuditResult.changedattribute)),
                {
                   
                    LogicalName: Text(Value.logicalName),
                    OldValue: If(IsBlank(ThisRecord.Value.oldValue), "null", Text(ThisRecord.Value.oldValue)),
                    NewValue: Text(Value.newValue)
                }
            ),
            // Else: changedData is just a plain string/int
            Collect(
                colParsedAuditData,
                {
                    
                    LogicalName: "",
                    OldValue: "",
                    NewValue: Text(ThisRecord.Value)
                }
            )
        )

        }
    )
);


Microsoft 365 and Office | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emmanuel Santana 32,745 Reputation points Independent Advisor
    2025-07-31T08:01:18.8366667+00:00

    Hello. Why are you mixing JSON strings and plain text or integers together in the same field without handling them separately? Have you checked if you’re referencing the right property for each audit record instead of a global variable?

    I mean, genuinely asking if this is intentional, like for example in this snippet:

    changedData: If(
        StartsWith(varAuditResult.changedattribute, "{") || StartsWith(varAuditResult.changedattribute, "["),
        // Trying to parse JSON here directly from varAuditResult.changedattribute
        ForAll(
            Table(ParseJSON(varAuditResult.changedattribute)),
            {
                LogicalName: Text(Value.logicalName),
                OldValue: If(IsBlank(ThisRecord.Value.oldValue), "null", Text(ThisRecord.Value.oldValue)),
                NewValue: Text(Value.newValue)
            }
        ),
        // Else treating changedattribute as plain text or integer
        Collect(
            colParsedAuditData,
            {
                LogicalName: "",
                OldValue: "",
                NewValue: Text(ThisRecord.Value)
            }
        )
    )
    
    
    

    In this snippet, varAuditResult.changedattribute is being used directly inside the loop for each audit record instead of Value.changeData, and there’s no proper check or separate handling for when changedattribute is just plain text or a number. This causes parsing errors and data inconsistency.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.