cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
david_ashworth
Helper I
Helper I

Trying to extract JSON array info

Hi all,

 

I am trying to extract certain information from a JSON array (that is provided via a webhook). Basically its a user onboarding through a platform that is then trying to run a flow to put the required info into a SharePoint list. The trouble i am having is getting the required info (user first name, last name, mobile etc...) into usable variables.

 

My flow works like this:

 

1. HTTP request received

2. Initialize variable

3. Select

 

david_ashworth_0-1627519670099.png

 

david_ashworth_1-1627519692987.png

 

david_ashworth_2-1627519711422.png

 

This is what i get out

 

david_ashworth_3-1627519748063.png

 

I have assigned a JSON ID field in the originating app to easily identify each response

 

[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
 
 
So this is where i get stuck, how do i pull out those question responses to then create a SharePoint list?
 
Appreciate any help.
 
Thanks,
David
1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Community Champion
Community Champion

Here is one possible solution for you. It works by taking the original JSON array data, transforming it into a simplified JSON object from which we can easily refer to each JSON property (First name, Last name, Job Title etc):

ekarim2020_5-1627987516734.png

This is the summary of the entire flow which you can create and follow along to determine if this will suit your needs:

ekarim2020_6-1627987718398.png

Starting with the raw JSON data:

ekarim2020_0-1627983895644.png

You can copy and paste the JSON below:

 

[
  {
    "Id": "first101",
    "Label": "First",
    "Value": "Bob"
  },
  {
    "Id": "last102",
    "Label": "Last",
    "Value": "Smith"
  },
  {
    "Id": "title103",
    "Label": "Job Title",
    "Value": "IT Manager"
  },
  {
    "Id": "mobile104",
    "Label": "Mobile Phone",
    "Value": "0123456789"
  }
]

 

Initialise three variables:

ekarim2020_2-1627984190326.png

Use Apply to each to iterate through all the JSON array. We build the a new JSON object, one property at a time in varQuestion. We add a new property to  varQuestion using the addProperty function starting with the first element in the (Compose My JSON) JSON array with ID="first101", then the next element with ID=last102, then title103 and finally mobile104:

ekarim2020_3-1627986206191.png

You can copy and past the following values for the above:

 

@{items('Apply_to_each')['Label']}
@{items('Apply_to_each')['Value']}
@{addProperty(variables('varQuestions'),variables('varLabel'), variables('varValue'))}
@{outputs('String_Property')}

 

We now have a new JSON object in varQuestions and it looks like this:

ekarim2020_0-1627988880785.png

We next add a Compose action using varQuestions as the input so that we can easily reference each property value:

ekarim2020_4-1627986632447.png

The input values for compose can be copied from here:

 

@{variables('varQuestions')}
@{outputs('Compose')['First']}
@{outputs('Compose')['Last']}
@{outputs('Compose')['Job Title']}
@{outputs('Compose')['Mobile Phone']}

 

We reference the properties using the following format:

ekarim2020_1-1627989059184.png

ekarim2020_0-1627990835025.png

And finally, you can add these values to a SharePoint list.

 

Hope this helps.

Ellis

View solution in original post

10 REPLIES 10
ekarim2020
Community Champion
Community Champion

What is the structure of the data being returned by Questions? Can you post the structure of the data you are getting?

If you can transform the data into this format:

 

[
  {
    "first": "Bob",
    "lastname": "Smith",
    "Job Title": "nothing",
    "mobile": "0123456789"
  }
]

 

 then you could use Parse JSON to easily refer to each data field:

ekarim2020_0-1627732472729.png

Ellis

Nived_Nambiar
Resolver I
Resolver I

Hi @david_ashworth 

There is another way for this too

 

see the workflow 

Nived_Nambiar_0-1627839752173.png

 

 

Here i had intialized the json data [for my demo]

after that i had used Parse JSON Action to parse the data from json data which is stored in Intialise variable action.

Now since there are many items, i used a Apply to each action and inside it i used the following parameters

Nived_Nambiar_1-1627839893061.png

 

 

Here i used body which need to be iterated here.

 

After that i used compose action to get the value of Label key,

 

For that i had used the following expression: 

items('Apply_to_each')?['Label']
 
Now i got the results like this
 
Nived_Nambiar_2-1627840177030.png

 

Nived_Nambiar_3-1627840192440.png

 

 

Like that etc etc..

 

Try this way

 

Mark it as solution if it resolves ur query

 

Regards,

Nived N

 

 

Hi @ekarim2020,

 

This is what i am getting from the HTTP request:

 

SCHEMA:

{
  "type""object",
  "properties": {
    "User": {
      "type""object",
      "properties": {
        "UserEmail": {
          "type""string"
        },
        "UserFirstName": {
          "type""string"
        },
        "UserLastName": {
          "type""string"
        },
        "UserMobile": {
          "type""string"
        },
        "UserPhone": {
          "type""string"
        },
        "UserPsaId": {
          "type""integer"
        },
        "UserOfficeId": {
          "type""string"
        },
        "UserIsAdmin": {
          "type""boolean"
        },
        "UserIsPriority": {
          "type""boolean"
        }
      }
    },
    "Company": {
      "type""object",
      "properties": {
        "CompanyName": {
          "type""string"
        },
        "CompanyPsaId": {
          "type""integer"
        },
        "CompanyTenantId": {
          "type""string"
        }
      }
    },
    "Ticket": {
      "type""object",
      "properties": {
        "TicketId": {
          "type""integer"
        },
        "TicketSubject": {
          "type""string"
        },
        "TicketDescription": {
          "type""string"
        },
        "TicketEstimatedTime": {
          "type""integer"
        },
        "CheckList": {
          "type""string"
        },
        "Script": {
          "type""string"
        },
        "Questions": {
          "type""array",
          "items": {
            "type""object",
            "properties": {
              "Id": {
                "type""string"
              },
              "Label": {
                "type""string"
              },
              "Value": {
                "type""string"
              }
            },
            "required": [
              "Id",
              "Label",
              "Value"
            ]
          }
        }
      }
    },
    "Feedback": {
      "type""object",
      "properties": {
        "FeedbackRating": {
          "type""integer"
        },
        "FeedbackSentiment": {
          "type""integer"
        },
        "FeedbackComment": {
          "type""string"
        },
        "FeedbackPhone": {
          "type""string"
        }
      }
    },
    "Routing": {
      "type""object",
      "properties": {
        "RoutingBoard": {
          "type""string"
        },
        "RoutingStatus": {
          "type""string"
        },
        "RoutingType": {
          "type""string"
        },
        "RoutingSubType": {
          "type""string"
        },
        "RoutingItem": {
          "type""string"
        },
        "RoutingPriority": {
          "type""string"
        },
        "RoutingSource": {
          "type""string"
        },
        "RoutingIsNeedsApproval": {
          "type""boolean"
        }
      }
    },
    "Agent": {
      "type""object",
      "properties": {
        "AgentId": {
          "type""integer"
        },
        "AgentFirstName": {
          "type""string"
        },
        "AgentLastName": {
          "type""string"
        },
        "AgentEmail": {
          "type""string"
        }
      }
    }
  }
}
 
 
And the QUESTIONS returns this:
 
[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
  },
  {
    "Id""\"Id\": \"18101\"",
    "Label""Random",
    "Value""C@nberra2021"
  }
]
 
I then try to initialize the variable as type Array and get this value of output:
 
[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
  },
  {
    "Id""\"Id\": \"18101\"",
    "Label""Random",
    "Value""P@ssword"
  }
]
 
 
Thanks for your help

Hi @Nived_Nambiar ,

 

So this is what i have in my flow:

 

david_ashworth_0-1627867853199.png

 

david_ashworth_1-1627867876642.png

 

david_ashworth_2-1627867904699.png

 

with Schema:

 

{
    "type""object",
    "properties": {
        "User": {
            "type""object",
            "properties": {
                "UserEmail": {
                    "type""string"
                },
                "UserFirstName": {
                    "type""string"
                },
                "UserLastName": {
                    "type""string"
                },
                "UserMobile": {
                    "type""string"
                },
                "UserPhone": {
                    "type""string"
                },
                "UserPsaId": {
                    "type""integer"
                },
                "UserOfficeId": {
                    "type""string"
                },
                "UserIsAdmin": {
                    "type""boolean"
                },
                "UserIsPriority": {
                    "type""boolean"
                }
            }
        },
        "Company": {
            "type""object",
            "properties": {
                "CompanyName": {
                    "type""string"
                },
                "CompanyPsaId": {
                    "type""integer"
                },
                "CompanyTenantId": {
                    "type""string"
                }
            }
        },
        "Ticket": {
            "type""object",
            "properties": {
                "TicketId": {
                    "type""integer"
                },
                "TicketSubject": {
                    "type""string"
                },
                "TicketDescription": {
                    "type""string"
                },
                "TicketEstimatedTime": {
                    "type""integer"
                },
                "CheckList": {
                    "type""string"
                },
                "Script": {
                    "type""string"
                },
                "Questions": {
                    "type""array",
                    "items": {
                        "type""object",
                        "properties": {
                            "Id": {
                                "type""string"
                            },
                            "Label": {
                                "type""string"
                            },
                            "Value": {
                                "type""string"
                            }
                        },
                        "required": [
                            "Id",
                            "Label",
                            "Value"
                        ]
                    }
                }
            }
        },
        "Feedback": {
            "type""object",
            "properties": {
                "FeedbackRating": {
                    "type""integer"
                },
                "FeedbackSentiment": {
                    "type""integer"
                },
                "FeedbackComment": {
                    "type""string"
                },
                "FeedbackPhone": {
                    "type""string"
                }
            }
        },
        "Routing": {
            "type""object",
            "properties": {
                "RoutingBoard": {
                    "type""string"
                },
                "RoutingStatus": {
                    "type""string"
                },
                "RoutingType": {
                    "type""string"
                },
                "RoutingSubType": {
                    "type""string"
                },
                "RoutingItem": {
                    "type""string"
                },
                "RoutingPriority": {
                    "type""string"
                },
                "RoutingSource": {
                    "type""string"
                },
                "RoutingIsNeedsApproval": {
                    "type""boolean"
                }
            }
        },
        "Agent": {
            "type""object",
            "properties": {
                "AgentId": {
                    "type""integer"
                },
                "AgentFirstName": {
                    "type""string"
                },
                "AgentLastName": {
                    "type""string"
                },
                "AgentEmail": {
                    "type""string"
                }
            }
        }
    }
}
 
david_ashworth_3-1627867949564.png

 

but the error i get is this:

 

david_ashworth_4-1627867992429.png

 

Thanks for your help on this

Nived_Nambiar
Resolver I
Resolver I

Hi @david_ashworth 

 

In the schema section can u generate the schema corresponding to the question http json response?

 

 

Hi @Nived_Nambiar ,

 

Sorry but my understanding of JSON is not great. So you mean the schema under the Parse section?

 

I have entered it like this:

 

david_ashworth_0-1627877213067.png

 

With the Schema:

 

{
    {
        {
            {
                },
                "Questions": {
                    "type""array",
                    "items": {
                        "type""object",
                        "properties": {
                            "Id": {
                                "type""string"
                            },
                            "Label": {
                                "type""string"
                            },
                            "Value": {
                                "type""string"
                            }
                        },
                        "required": [
                            "Id",
                            "Label",
                            "Value"
                        ]
                    }
                }
            }
        }
    },
}
 
But it says this is invalid? I have incorrectly formatted it but not sure where
 
Thanks
Nived_Nambiar
Resolver I
Resolver I

Hi @david_ashworth 

You can create the schema from sample json which u showed us as example, just click on that Generate Schema from sample and then add the json u had and then it automatically schema for you!!

 

Regards,

Nived N

Hi @Nived_Nambiar ,

 

Sorry but im not sure i fully understand what you are suggesting. So i have used the sample JSON and entered it into the PARSE action but the error is "ValidationFailed. The schema validation failed." And then under outputs the error states:

 

[
  {
    "message""Invalid type. Expected Object but got Array.",
    "lineNumber"0,
    "linePosition"0,
    "path""",
    "schemaId""#",
    "errorType""type",
    "childErrors": []
  }
]
 
When editing the PARSE JSON Flow, under sample schema i am putting this in (is this correct? If not could you please advise what text i need to put in?):
 
{
  "type""object",
  "properties": {
    "User": {
      "type""object",
      "properties": {
        "UserEmail": {
          "type""string"
        },
        "UserFirstName": {
          "type""string"
        },
        "UserLastName": {
          "type""string"
        },
        "UserMobile": {
          "type""string"
        },
        "UserPhone": {
          "type""string"
        },
        "UserPsaId": {
          "type""integer"
        },
        "UserOfficeId": {
          "type""string"
        },
        "UserIsAdmin": {
          "type""boolean"
        },
        "UserIsPriority": {
          "type""boolean"
        }
      }
    },
    "Company": {
      "type""object",
      "properties": {
        "CompanyName": {
          "type""string"
        },
        "CompanyPsaId": {
          "type""integer"
        },
        "CompanyTenantId": {
          "type""string"
        }
      }
    },
    "Ticket": {
      "type""object",
      "properties": {
        "TicketId": {
          "type""integer"
        },
        "TicketSubject": {
          "type""string"
        },
        "TicketDescription": {
          "type""string"
        },
        "TicketEstimatedTime": {
          "type""integer"
        },
        "CheckList": {
          "type""string"
        },
        "Script": {
          "type""string"
        },
        "Questions": {
          "type""array",
          "items": {
            "type""object",
            "properties": {
              "Id": {
                "type""string"
              },
              "Label": {
                "type""string"
              },
              "Value": {
                "type""string"
              }
            },
            "required": [
              "Id",
              "Label",
              "Value"
            ]
          }
        }
      }
    },
    "Feedback": {
      "type""object",
      "properties": {
        "FeedbackRating": {
          "type""integer"
        },
        "FeedbackSentiment": {
          "type""integer"
        },
        "FeedbackComment": {
          "type""string"
        },
        "FeedbackPhone": {
          "type""string"
        }
      }
    },
    "Routing": {
      "type""object",
      "properties": {
        "RoutingBoard": {
          "type""string"
        },
        "RoutingStatus": {
          "type""string"
        },
        "RoutingType": {
          "type""string"
        },
        "RoutingSubType": {
          "type""string"
        },
        "RoutingItem": {
          "type""string"
        },
        "RoutingPriority": {
          "type""string"
        },
        "RoutingSource": {
          "type""string"
        },
        "RoutingIsNeedsApproval": {
          "type""boolean"
        }
      }
    },
    "Agent": {
      "type""object",
      "properties": {
        "AgentId": {
          "type""integer"
        },
        "AgentFirstName": {
          "type""string"
        },
        "AgentLastName": {
          "type""string"
        },
        "AgentEmail": {
          "type""string"
        }
      }
    }
  }
}
 
 
 
Thanks,
David
ekarim2020
Community Champion
Community Champion

Here is one possible solution for you. It works by taking the original JSON array data, transforming it into a simplified JSON object from which we can easily refer to each JSON property (First name, Last name, Job Title etc):

ekarim2020_5-1627987516734.png

This is the summary of the entire flow which you can create and follow along to determine if this will suit your needs:

ekarim2020_6-1627987718398.png

Starting with the raw JSON data:

ekarim2020_0-1627983895644.png

You can copy and paste the JSON below:

 

[
  {
    "Id": "first101",
    "Label": "First",
    "Value": "Bob"
  },
  {
    "Id": "last102",
    "Label": "Last",
    "Value": "Smith"
  },
  {
    "Id": "title103",
    "Label": "Job Title",
    "Value": "IT Manager"
  },
  {
    "Id": "mobile104",
    "Label": "Mobile Phone",
    "Value": "0123456789"
  }
]

 

Initialise three variables:

ekarim2020_2-1627984190326.png

Use Apply to each to iterate through all the JSON array. We build the a new JSON object, one property at a time in varQuestion. We add a new property to  varQuestion using the addProperty function starting with the first element in the (Compose My JSON) JSON array with ID="first101", then the next element with ID=last102, then title103 and finally mobile104:

ekarim2020_3-1627986206191.png

You can copy and past the following values for the above:

 

@{items('Apply_to_each')['Label']}
@{items('Apply_to_each')['Value']}
@{addProperty(variables('varQuestions'),variables('varLabel'), variables('varValue'))}
@{outputs('String_Property')}

 

We now have a new JSON object in varQuestions and it looks like this:

ekarim2020_0-1627988880785.png

We next add a Compose action using varQuestions as the input so that we can easily reference each property value:

ekarim2020_4-1627986632447.png

The input values for compose can be copied from here:

 

@{variables('varQuestions')}
@{outputs('Compose')['First']}
@{outputs('Compose')['Last']}
@{outputs('Compose')['Job Title']}
@{outputs('Compose')['Mobile Phone']}

 

We reference the properties using the following format:

ekarim2020_1-1627989059184.png

ekarim2020_0-1627990835025.png

And finally, you can add these values to a SharePoint list.

 

Hope this helps.

Ellis

View solution in original post

Hi @ekarim2020 ,

 

Thank you so much this has worked perfectly, exactly what i needed. Appreciate your help and the very helpful (and detailed) steps

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,158)