cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SaifAli
Level: Powered On

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
Community Support Team
Community Support Team

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
Super User
Super User

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!



Community Support Team
Community Support Team

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.

SaifAli
Level: Powered On

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"

}
]
}

Community Support Team
Community Support Team

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

SaifAli
Level: Powered On

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

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

SaifAli
Level: Powered On

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.
SaifAli
Level: Powered On

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
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 100 members 1,910 guests
Please welcome our newest community members: