cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Dual Super User III
Dual Super User III

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
Highlighted
Dual Super User III
Dual Super User III

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
Frequent Visitor

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

Highlighted
Dual Super User III
Dual Super User III

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

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

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 (6,160)