cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PaulT
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
yashag2255
Dual Super User II
Dual Super User II

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
yashag2255
Dual Super User II
Dual Super User II

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!

PaulT
Frequent Visitor

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

yashag2255
Dual Super User II
Dual Super User II

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
MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (68,738)