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 Automate / Convert String to Json
Power Automate
Unanswered

Convert String to Json

(0) ShareShare
ReportReport
Posted on by

I have the below String (Received from a Different Flow as an input parameter)

[{
krishnendu.barman@abc.com,
48,
2
}],[{
s.hussain.mansuri@abc.com,
25,
1
}],[{
varsha.balu.swami@abc.com,
43,
2
}]

 

and I want that string to convert to the below Json Format

 

{
  "Name""Employee Record",
  "Description""My Description",
  "Items": [
    {
      "FieldValues": {
        "ResponseTime"48,
        "Score"2,
        "Email""abc@abc.com"
      }
    },
    {
      "FieldValues": {
        "ResponseTime"25,
        "Score"1,
        "Email""abc@abc.com"
      }
    },
    {
      "FieldValues": {
        "ResponseTime"43,
        "Score"2,
        "Email""abc@abc.com"
      }
    }
  ]
}
 
 
I am new to the power Automate, your help will be appreciated 
Categories:
I have the same question (0)
  • Ellis Karim Profile Picture
    11,681 Super User 2025 Season 2 on at

    Here is the flow that could help achieve your desired outcome:

    2021-09-25_14-16-23.jpg

    (1) The varEmployeeData variable will be used to store the employee records in JSON format:

    ekarim2020_0-1632571034454.png

    (2) The varFieldValues variable will be used to store the field values for each employee:

    2021-09-25_13-09-37.jpg

    (3) For the following variable we just need a blank line so just press Enter:

    ekarim2020_1-1632571102775.png

    We need this because later in the flow we will be cleaning up the source data and we will need to remote new line characters from the source data

    2021-09-25_13-01-23.gif

    (4) This variable will store your source data. I just pasted in what you had posted:

    2021-09-25_13-05-05.jpg

    (5) Next, we use three compose actions to clean up and format your source data:

    2021-09-25_13-16-29.jpg

    Here are the expressions for those compose actions:

    2021-09-25_13-27-12-1.jpg

    2021-09-25_13-31-12-2.jpg2021-09-25_13-34-10-3.jpg

    Here are the expressions that you can copy-and-paste:

     

     

    (1) Compose Replace NewLine
    replace(variables('varSourceDataString'),variables('varNewLine'),'')
    
    (2) Replace Record Separators
    replace(outputs('Compose_Replace_NewLine'),'],[',']#[')
    
    (3) Compose Split Employee Records
    split(outputs('Replace_Record_Separators'),'#')

     

    (6) Next, add an Apply to Each loop:

    2021-09-25_13-41-30.jpg

    (7) Next add a compose action which will separate each employee record from the source string:

    2021-09-25_13-50-17.jpg

     

    split(replace(replace(item(),'[{',''),'}]',''),',')

     

    (8) Next we create the employee record in JSON format:

     

    2021-09-25_13-54-55.jpg

    Here is a close up of the format:

    2021-09-25_14-09-19.jpg

    (9) Then add the employee record to the Employee Data. This is the last action of the Apply to each loop

    ekarim2020_0-1632575601914.png

    (10) Finally we put all the pieces together into a single JSON object that contains all the employee records inside the Items array:

    2021-09-25_14-19-46.jpg

    After the flow is run, the Compose Employee Data contains:

    2021-09-25_14-22-03.jpg

    (11) Using a compose action to test the output:

    ekarim2020_2-1632577085955.png

     

    outputs('Compose_Employee_Data')['Items'][0]['FieldValues/Email'] --> krishnendu.barman@abc.com
    outputs('Compose_Employee_Data')['Items'][1]['FieldValues/Email'] --> s.hussain.mansuri@abc.com
    outputs('Compose_Employee_Data')['Items'][2]['FieldValues/Email'] --> varsha.balu.swami@abc.com

     

    You can reference the other properties using the following expressions:

     

    outputs('Compose_Employee_Data')['Items'][0]['FieldValues/Email'] --> krishnendu.barman@abc.com
    outputs('Compose_Employee_Data')['Items'][1]['FieldValues/Email'] --> s.hussain.mansuri@abc.com
    outputs('Compose_Employee_Data')['Items'][2]['FieldValues/Email'] --> varsha.balu.swami@abc.com
    
    outputs('Compose_Employee_Data')['Items'][0]['FieldValues/ResponseTime'] --> 48
    outputs('Compose_Employee_Data')['Items'][1]['FieldValues/ResponseTime'] --> 25
    outputs('Compose_Employee_Data')['Items'][2]['FieldValues/ResponseTime'] --> 43
    
    outputs('Compose_Employee_Data')['Items'][0]['FieldValues/Score'] --> 2
    outputs('Compose_Employee_Data')['Items'][1]['FieldValues/Score'] --> 1
    outputs('Compose_Employee_Data')['Items'][2]['FieldValues/Score'] --> 2

     

    Ellis


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

  • Hamza_Ahmed Profile Picture
    2 on at

    Problem Statement
    Trigger return response in Text format need to make a json object.

     

    Solution:

    Encode the response by using EncodedUriComponent expression.

    I have done some work on the response String to convert to JSON format.
    In my case, I getting responses from Update App (Dynamic 365) like this:

    Response Start


    Question1
    provide the details

     

    Richt text Question
    <p>dasda</p>

     

    Number Question
    3223

     

    Multiple Choice Question
    ["Option 2"]

     

    Single Choice Question
    Option 2

     

    Dropdown Question
    Option 1

     

    Date Question
    2024-02-20

     

    Response End


    Step 1:
    Encode String/json Response using EncodeUriComponent Expression.

    Result EncodeURICOMPONENT :

    Question1%0AI%20provided%20the%20details%3F%0A%0ARicht%20text%20Question%0A%3Cp%3EI%20need%20more%20info%20dasdasd%3Cbr%3Edfsafsdfsdf%3Cbr%3Efdsfsdf%3C%2Fp%3E%0A%0ANumber%20Question%0A324324%0A%0AMultiple%20Choice%20Question%0A%5B%22Option%201%22%2C%22Option%202%22%5D%0A%0ASingle%20Choice%20Question%0AOption%201%0A%0ADropdown%20Question%0AOption%201%0A%0ADate%20Question%0A2024-01-29

    Step 2:

    Split the encoded response with your condition characters in my case.

    '%0A%0A'

    Hamza_Ahmed_0-1709105322192.png

     

    Step 3 :

    Manipulate String to create JSON schema

    Hamza_Ahmed_2-1709105451351.png

    Step 4:

    Convert JSON into JSON object.

    Hamza_Ahmed_1-1709105427207.png

     

    Hope you understand how to create JSON @ekarim2020  Convert String into an Object? 
    Dynamically Parse JSON as object or Array 

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard