cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

Pulling the data from JSON output and creating an array

Hi Team,

 

So below is the sample of my http request output

 

2.PNG

 

from here i need to pull the "text" tag which resides inside the integer tag (0,1,2 etc.)

 

it is easy if there's a single integer for "0" , it will be like "body('HTTP')?['comments']?[0]?['text']"

 

but i need to get all the texts from 0,1,2,3 etc. like this "body('HTTP')?['comments']?[1]?['text']", "body('HTTP')?['comments']?[2]?['text']" etc.   and the problem is the value could go up to 40 or 50 and its dynamic. 

 

I somehow can get the total count of comments from "count" tag

"body('HTTP')?['Count']"
 
but is there a way to loop through that count and create an array of all the comments ( text tag inside that ) ?
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Pulling the data from JSON output and creating an array

Hi @SaifAli ,

 

You could refer to screenshot below to create the flow:

1.png2.png

Note:

1. You could add the JSON output in the Compose.

2. For the schema in the Parse Json action, you could enter the schema as below:

{
    "type": "object",
    "properties": {
        "totalCount": {
            "type": "integer"
        },
        "count": {
            "type": "integer"
        },
        "comments": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "workItemId": {
                        "type": "integer"
                    },
                    "id": {
                        "type": "integer"
                    },
                    "version": {
                        "type": "integer"
                    },
                    "text": {
                        "type": "string"
                    },
                    "createdDate": {
                        "type": "string"
                    }
                },
                "required": [
                    "workItemId",
                    "id",
                    "version",
                    "text",
                    "createdDate"
                ]
            }
        }
    }
}

Or you could Use sample payload to generate schema, just copy and paste all the json text in the pop-up windown as screenshot below:

3.png

 

The flow would run successfully to create the array as below:

4.png

 

Please let me know if your problem could be solved.

 

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Highlighted
Super User III
Super User III

Re: Pulling the data from JSON output and creating an array

Hi @SaifAli 

 

Believe it is possible. Could you please post your JSON file as text so that I could try this and let you know?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Highlighted
Community Support
Community Support

Re: Pulling the data from JSON output and creating an array

Hi @SaifAli ,

 

As @abm  asked, please share the full JSON so we could make a test and provide a proper workaround for you.

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
Helper II
Helper II

Re: Pulling the data from JSON output and creating an array

Hi Guys,

 

Thanks for your prompt replies, here is the full JSON you can work with ( I've removed few tags because of my organization's security policies, hope you understand )

 

{
"totalCount": 5,
"count": 5,
"comments": [
{
"workItemId": 166894,
"id": 2635035,
"version": 1,
"text": "Adding the necessary spec",
"createdDate": "2019-08-20T10:06:39.173Z"
},
{
"workItemId": 166894,
"id": 2635033,
"version": 1,
"text": "Adding the necessary spec",
"createdDate": "2019-08-20T10:03:39.77Z"
},
{
"workItemId": 166894,
"id": 2635032,
"version": 1,
"text": "Adding the necessary spec",
"createdDate": "2019-08-20T10:00:23.91Z"
},
{
"workItemId": 166894,
"id": 2635027,
"version": 1,
"text": "Adding the necessary spec",
"createdDate": "2019-08-20T09:50:57.207Z"
},
{
"workItemId": 166894,
"id": 2609309,
"version": 1,
"text": "<div><span>@internal This is internal test</span></div>",
"createdDate": "2019-08-12T12:50:03.88Z"

}
]
}

Highlighted
Community Support
Community Support

Re: Pulling the data from JSON output and creating an array

Hi @SaifAli ,

 

You could refer to screenshot below to create the flow:

1.png2.png

Note:

1. You could add the JSON output in the Compose.

2. For the schema in the Parse Json action, you could enter the schema as below:

{
    "type": "object",
    "properties": {
        "totalCount": {
            "type": "integer"
        },
        "count": {
            "type": "integer"
        },
        "comments": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "workItemId": {
                        "type": "integer"
                    },
                    "id": {
                        "type": "integer"
                    },
                    "version": {
                        "type": "integer"
                    },
                    "text": {
                        "type": "string"
                    },
                    "createdDate": {
                        "type": "string"
                    }
                },
                "required": [
                    "workItemId",
                    "id",
                    "version",
                    "text",
                    "createdDate"
                ]
            }
        }
    }
}

Or you could Use sample payload to generate schema, just copy and paste all the json text in the pop-up windown as screenshot below:

3.png

 

The flow would run successfully to create the array as below:

4.png

 

Please let me know if your problem could be solved.

 

 

Best regards,

Alice       

 

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Helper II
Helper II

Re: Pulling the data from JSON output and creating an array

Thanks @v-alzhan-msft  I'll try this

Highlighted
Helper II
Helper II

Re: Pulling the data from JSON output and creating an array

Hi @v-alzhan-msft  

 

Can you please elaborate me the value of this :

 

Capture.PNG

At first I tried 

"Items('Apply_to_each')?['text']" and got a conversion error from string to array
 
and then i tried this "array(Items('Apply_to_each')?['text'])" which only resulted putting the last value in the array.
Highlighted
Helper II
Helper II

Re: Pulling the data from JSON output and creating an array

I got it , I was using "set variable" instead of "append to string variable" 

 

Now its working fine thanks

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (4,377)