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

HTTP output object instead of array - how to process?

Hi,

I have an HTTP action and its output is not a JSON array, only nested objects as far as I can tell. Here's the schema I generated from the HTTP output payload via the "Parse JSON" action:

 

{
    "type": "object",
    "properties": {
        "id": {
            "type": "string"
        },
        "type": {
            "type": "string"
        },
        "status": {
            "type": "string"
        },
        "title": {
            "type": "string"
        },
        "space": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "key": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                },
                "_links": {
                    "type": "object",
                    "properties": {
                        "webui": {
                            "type": "string"
                        },
                        "self": {
                            "type": "string"
                        }
                    }
                },
                "_expandable": {
                    "type": "object",
                    "properties": {
                        "metadata": {
                            "type": "string"
                        },
                        "icon": {
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "homepage": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "version": {
            "type": "object",
            "properties": {
                "by": {
                    "type": "object",
                    "properties": {
                        "type": {
                            "type": "string"
                        },
                        "username": {
                            "type": "string"
                        },
                        "userKey": {
                            "type": "string"
                        },
                        "profilePicture": {
                            "type": "object",
                            "properties": {
                                "path": {
                                    "type": "string"
                                },
                                "width": {
                                    "type": "integer"
                                },
                                "height": {
                                    "type": "integer"
                                },
                                "isDefault": {
                                    "type": "boolean"
                                }
                            }
                        },
                        "displayName": {
                            "type": "string"
                        },
                        "_links": {
                            "type": "object",
                            "properties": {
                                "self": {
                                    "type": "string"
                                }
                            }
                        },
                        "_expandable": {
                            "type": "object",
                            "properties": {
                                "status": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "when": {
                    "type": "string"
                },
                "message": {
                    "type": "string"
                },
                "number": {
                    "type": "integer"
                },
                "minorEdit": {
                    "type": "boolean"
                },
                "hidden": {
                    "type": "boolean"
                },
                "_links": {
                    "type": "object",
                    "properties": {
                        "self": {
                            "type": "string"
                        }
                    }
                },
                "_expandable": {
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "container": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "key": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                },
                "_links": {
                    "type": "object",
                    "properties": {
                        "webui": {
                            "type": "string"
                        },
                        "self": {
                            "type": "string"
                        }
                    }
                },
                "_expandable": {
                    "type": "object",
                    "properties": {
                        "metadata": {
                            "type": "string"
                        },
                        "icon": {
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "homepage": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "body": {
            "type": "object",
            "properties": {
                "view": {
                    "type": "object",
                    "properties": {
                        "value": {
                            "type": "string"
                        },
                        "representation": {
                            "type": "string"
                        },
                        "_expandable": {
                            "type": "object",
                            "properties": {
                                "webresource": {
                                    "type": "string"
                                },
                                "content": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "_expandable": {
                    "type": "object",
                    "properties": {
                        "editor": {
                            "type": "string"
                        },
                        "export_view": {
                            "type": "string"
                        },
                        "styled_view": {
                            "type": "string"
                        },
                        "storage": {
                            "type": "string"
                        },
                        "anonymous_export_view": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "extensions": {
            "type": "object",
            "properties": {
                "position": {
                    "type": "string"
                }
            }
        },
        "_links": {
            "type": "object",
            "properties": {
                "webui": {
                    "type": "string"
                },
                "edit": {
                    "type": "string"
                },
                "tinyui": {
                    "type": "string"
                },
                "collection": {
                    "type": "string"
                },
                "base": {
                    "type": "string"
                },
                "context": {
                    "type": "string"
                },
                "self": {
                    "type": "string"
                }
            }
        },
        "_expandable": {
            "type": "object",
            "properties": {
                "metadata": {
                    "type": "string"
                },
                "operations": {
                    "type": "string"
                },
                "children": {
                    "type": "string"
                },
                "restrictions": {
                    "type": "string"
                },
                "history": {
                    "type": "string"
                },
                "ancestors": {
                    "type": "string"
                },
                "descendants": {
                    "type": "string"
                }
            }
        }
    }
}

I would like to be able to further process this data with actions such as "Select" and "Create HTML Table". But unfortunately, in the respective follow-up action I don't get any dynamic properties to choose from. Normally, this would be the case if "Parse JSON" had a JSON array to start out with.

 

If Iin the follow-up action I try to set the expression "body('Parse_JSON) I get the error message: "BadRequest. The 'from' property value in the 'select' action inputs is of type 'Object'. The value must be an array."

 

So clearly there's no way to continue if I don't get the JSON object to become an array somehow. I also tried to alter the schema and set every "type: "object" to noit use a type, i.e. "{} - didn't help either.

 

Can anybody help me out here?

 

Thanks a lot!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @colonel_claypoo 

 

Since all the values in the response is of type object, what you can do it:
 
1) Parse the JSON response.
2) Create an Empty array variable.
3) Append the Parse JSON body into this array variable.
4) In the Select action, in the From select this newly created array variable.
5) In the key and Value, you need to use expression:
first(variables('test1'))['id']
 
This will fetch the ID. If you want a second level value, expression will become:
first(variables('test1'))['space']['id']
 
Test1 is the name of my array variable. Please refer to attached screenshot for more details.
MicrosoftTeams-image (181).png

 

 

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

6 REPLIES 6
Dual Super User II
Dual Super User II

Hi @colonel_claypoo 

 

You can initialise an empty array variable in the beginning of your flow. Now after the parse JSON action, add an apply to each control and select the body from the parse json action and then within the loop add an action to append to array variable. In the value, select current item (or create the columns: values as desired). Now outside of the apply to each loop add the action create HTML table and select the array here. 

 

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!

@yashag2255, thanks for your help. Unfortunately, I cannot use "Apply to each" on the "Pase JSON" body for the very same reason, it is an object, not an array. There's no body to choose in the dynamic content pane. Manually putting "body('Parse_JSON)" in the "Apply to each" action throws the following error: "ExpressionEvaluationFailed. The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')' is of type 'Object'. The result must be a valid array"
I believe in the JSON schema an array must be defined for such an action to work. Do you have another idea?

Thanks.

@colonel_claypoo 

 

I see. Can you please share a sample of the data you are getting? Maybe we can modify the JSON schema somewhat and attempt this. 

@yashag2255, sure. Here's the payload output from the HTTP Rest call (... where I hid sensitive informaiton):

 

{
  "id": "901875409",
  "type": "page",
  "status": "current",
  "title": "\"Follow up\"",
  "space": {
    "id": 203423745,
    "key": "DFIN",
    "name": "...",
    "type": "global",
    "_links": {
      "webui": "/display/DFIN",
      "self": "https://.../rest/api/space/DFIN"
    },
    "_expandable": {
      "metadata": "",
      "icon": "",
      "description": "",
      "homepage": "/rest/api/content/203063616"
    }
  },
  "version": {
    "by": {
      "type": "known",
      "username": "klf",
      "userKey": "2c95a9e761877ae90161893354fd0003",
      "profilePicture": {
        "path": "/user-avatar",
        "width": 48,
        "height": 48,
        "isDefault": false
      },
      "displayName": "...",
      "_links": {
        "self": "https://.../rest/api/user?key=2c95a9e761877ae90161893354fd0003"
      },
      "_expandable": {
        "status": ""
      }
    },
    "when": "2019-07-09T13:22:39.690+02:00",
    "message": "",
    "number": 8,
    "minorEdit": false,
    "hidden": false,
    "_links": {
      "self": "https://.../rest/experimental/content/901875409/version/8"
    },
    "_expandable": {
      "content": "/rest/api/content/901875409"
    }
  },
  "container": {
    "id": 203423745,
    "key": "DFIN",
    "name": "...",
    "type": "global",
    "_links": {
      "webui": "/display/DFIN",
      "self": "https://.../rest/api/space/DFIN"
    },
    "_expandable": {
      "metadata": "",
      "icon": "",
      "description": "",
      "homepage": "/rest/api/content/203063616"
    }
  },
  "body": {
    "view": {
      "value": "<div class=.../div>",
      "representation": "storage",
      "_expandable": {
        "webresource": "",
        "content": "/rest/api/content/901875409"
      }
    },
    "_expandable": {
      "editor": "",
      "export_view": "",
      "styled_view": "",
      "storage": "",
      "anonymous_export_view": ""
    }
  },
  "extensions": {
    "position": "none"
  },
  "_links": {
    "webui": "/pages/viewpage.action?pageId=901875409",
    "edit": "/pages/resumedraft.action?draftId=901875409&draftShareId=19888f94-ae08-4bf7-bc69-81d31b7c4337",
    "tinyui": "/x/0YbBNQ",
    "collection": "/rest/api/content",
    "base": "https://...",
    "context": "/...",
    "self": "https://.../rest/api/content/901875409"
  },
  "_expandable": {
    "metadata": "",
    "operations": "",
    "children": "/rest/api/content/901875409/child",
    "restrictions": "/rest/api/content/901875409/restriction/byOperation",
    "history": "/rest/api/content/901875409/history",
    "ancestors": "",
    "descendants": "/rest/api/content/901875409/descendant"
  }
}

Hi @colonel_claypoo 

 

Since all the values in the response is of type object, what you can do it:
 
1) Parse the JSON response.
2) Create an Empty array variable.
3) Append the Parse JSON body into this array variable.
4) In the Select action, in the From select this newly created array variable.
5) In the key and Value, you need to use expression:
first(variables('test1'))['id']
 
This will fetch the ID. If you want a second level value, expression will become:
first(variables('test1'))['space']['id']
 
Test1 is the name of my array variable. Please refer to attached screenshot for more details.
MicrosoftTeams-image (181).png

 

 

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

Hi @yashag2255, sorry didn't get around to checking yet but will do so soon and report back. Thanks.

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (29,243)