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

Creating a CSV from an array inside of an array

I am using the Namely API to request the results of a report into a Microsft Flow. I then need to take the results of this and convert into a CSV table. The problem I am running into is the data is an array inside of another array. The JSON schema that is generate is as follows:

{
    "type": "object",
    "properties": {
        "reports": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "type": {
                        "type": "string"
                    },
                    "columns": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "type": {
                                    "type": "string"
                                },
                                "label": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "content": {
                        "type": "array",
                        "items": {
                            "type": "array"
                        }
                    }
                }
            }
        }
    }
}
The part that I am interested in is in red.
Basically, this an array of "reports" (which will always be only one array) which contains an array of "columns" (the column headers) and the array of "content" (which is the data I need). Some sample data is below. Does anybody know how I can use flow to create a CSV using this information? 
{
  "reports": [
    {
      "id": "53a4340a-b025-4d32-bd8f-2aa435b268b7",
      "type": "profile",
      "columns": [
        {
          "name": "profiles_guid",
          "type": "text",
          "label": "GUID"
        },
        {
          "name": "profiles_first_name",
          "type": "text",
          "label": "First name"
        },
        {
          "name": "profiles_last_name",
          "type": "text",
          "label": "Last name"
        },
        {
          "name": "profiles_email",
          "type": "text",
          "label": "Company email"
        },
        {
          "name": "profiles_start_date",
          "type": "date",
          "label": "Start date"
        },
        {
          "name": "profiles_employee_type",
          "type": "text",
          "label": "Employee type"
        },
        {
          "name": "profiles_category_6696",
          "type": "text",
          "label": "Department"
        }
      ],
      "content": [
        [
          "739675e7-2041-46a7-8965-691a5dac37cc",
          "Alice",
          "James",
          "AJames@none.com",
          "09/03/2019",
          "Full Time",
          "IT"
        ],
        [
          "8dba6571-abba-4fbc-b0b6-9858af6858e2",
          "Paul",
          "Jones",
          "PJones@none.com",
          "08/01/2019",
          "Part Time",
          "Human Resources"
        ]
      ],
      "links": {}
    }
  ],
  "meta": {},
  "links": {},
  "linked": {}
}
Thanks in advance,
 
Paul
1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Creating a CSV from an array inside of an array

Hi @PaulT 

 

You can update your flow as:MicrosoftTeams-image (176).png
Expression used on Append to Array Variable:
 
{"Key1":"items('Apply_to_each_2')[0]","Key2":"items('Apply_to_each_2')[1]","Key2":"items('Apply_to_each_2')[3]","Key3":"items('Apply_to_each_2')[4]","Key4":"items('Apply_to_each_2')[5]","Key5":"items('Apply_to_each_2')[6]","Key6":"items('Apply_to_each_2')[7]"}

 

Hope This Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

 

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Creating a CSV from an array inside of an array

HI @PaulT 

 

Please see the screenshots below:

 

 

MicrosoftTeams-image (165).png

 

MicrosoftTeams-image (166).png

I have passed the JSON as an object in the intialise variable action and used the compose actions for the result. 

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Highlighted
PaulT
Level: Powered On

Re: Creating a CSV from an array inside of an array

Thanks @yashag2255  but that only seems to get me the column headers. What I am trying to get to is the Content section. What I would like to end up with is a CSV with the following data:

 

"739675e7-2041-46a7-8965-691a5dac37cc","Alice","James","AJames@none.com","09/03/2019","Full Time","IT"
"8dba6571-abba-4fbc-b0b6-9858af6858e2","Paul","Jones","PJones@none.com","08/01/2019","Part Time","Human Resources"

 

I am stuggling with taking an array of objects and getting them to be the rows of a CSV

Super User
Super User

Re: Creating a CSV from an array inside of an array

Hi @PaulT 

 

You can update your flow as:MicrosoftTeams-image (176).png
Expression used on Append to Array Variable:
 
{"Key1":"items('Apply_to_each_2')[0]","Key2":"items('Apply_to_each_2')[1]","Key2":"items('Apply_to_each_2')[3]","Key3":"items('Apply_to_each_2')[4]","Key4":"items('Apply_to_each_2')[5]","Key5":"items('Apply_to_each_2')[6]","Key6":"items('Apply_to_each_2')[7]"}

 

Hope This Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

 

View solution in original post

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

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

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 Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 288 members 3,703 guests
Please welcome our newest community members: