Home > Blockchain >  Azure Logic App returning hard to use json strings
Azure Logic App returning hard to use json strings

Time:08-12

I am currently stuck trying to convert JSON strings into a useable format.

The data was originally in a pandas dataframe, and I have it stored in JSON format in a azure blob storage container. I then used this Compose base64(outputs('Get_blob_content_(V2)')?['body']) , then used base64ToString(outputs('Compose')) to push the JSON file into string data type.

Afterwards I have parsed it using Parse JSON function.

My current Attempt

currently when I email it, I'm getting a list of sorts of the JSON entries. I would like to put this into a tabular format or table format. I have tried both the CSV and HTML function options but neither do anything.

enter image description here

CodePudding user response:

After reproducing from our end, we could able to achieve your requirement using the below flow.

enter image description here

Below is the json I'm working on

{
  "0": "2022-08-12 16:00:00",
  "1": "2022-09-05 16:00:00",
  "2": "2022-09-05 16:00:00",
  "3": "2022-09-01 16:00:00",
  "4": "2022-09-03 16:00:00",
  "5": "2022-09-21 16:00:00",
  "6": "2022-09-23 16:00:00",
  "7": "2022-09-29 10:00:00",
  "8": "2022-10-07 16:00:00",
  "9": "2022-09-30 16:00:00",
  "10": "2022-10-07 17:00:00",
  "11": "2022-10-21 16:00:00"
}

enter image description here

In Create HTML table I have actually used the Parse JSON's results.

enter image description here

RESULTS:

Below is the successful run in my logic app

enter image description here

In my mail

enter image description here

Here is the code view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": {
                    "0": "2022-08-12 16:00:00",
                    "1": "2022-09-05 16:00:00",
                    "2": "2022-09-05 16:00:00",
                    "3": "2022-09-01 16:00:00",
                    "4": "2022-09-03 16:00:00",
                    "5": "2022-09-21 16:00:00",
                    "6": "2022-09-23 16:00:00",
                    "7": "2022-09-29 10:00:00",
                    "8": "2022-10-07 16:00:00",
                    "9": "2022-09-30 16:00:00",
                    "10": "2022-10-07 17:00:00",
                    "11": "2022-10-21 16:00:00"
                },
                "runAfter": {},
                "type": "Compose"
            },
            "Create_HTML_table": {
                "inputs": {
                    "columns": [
                        {
                            "header": "0",
                            "value": "@body('Parse_JSON')?['0']"
                        },
                        {
                            "header": "1",
                            "value": "@body('Parse_JSON')?['1']"
                        },
                        {
                            "header": "2",
                            "value": "@body('Parse_JSON')?['2']"
                        },
                        {
                            "header": "3",
                            "value": "@body('Parse_JSON')?['3']"
                        },
                        {
                            "header": "4",
                            "value": "@body('Parse_JSON')?['4']"
                        },
                        {
                            "header": "5",
                            "value": "@body('Parse_JSON')?['5']"
                        },
                        {
                            "header": "6",
                            "value": "@body('Parse_JSON')?['6']"
                        },
                        {
                            "header": "7",
                            "value": "@body('Parse_JSON')?['7']"
                        },
                        {
                            "header": "8",
                            "value": "@body('Parse_JSON')?['8']"
                        },
                        {
                            "header": "9",
                            "value": "@body('Parse_JSON')?['9']"
                        },
                        {
                            "header": "10",
                            "value": "@body('Parse_JSON')?['10']"
                        },
                        {
                            "header": "11",
                            "value": "@body('Parse_JSON')?['11']"
                        }
                    ],
                    "format": "HTML",
                    "from": "@array(outputs('Compose'))"
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Table"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@outputs('Compose')",
                    "schema": {
                        "properties": {
                            "0": {
                                "type": "string"
                            },
                            "1": {
                                "type": "string"
                            },
                            "2": {
                                "type": "string"
                            },
                            "3": {
                                "type": "string"
                            },
                            "4": {
                                "type": "string"
                            },
                            "5": {
                                "type": "string"
                            },
                            "6": {
                                "type": "string"
                            },
                            "7": {
                                "type": "string"
                            },
                            "8": {
                                "type": "string"
                            },
                            "9": {
                                "type": "string"
                            },
                            "10": {
                                "type": "string"
                            },
                            "11": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "ParseJson"
            },
            "Send_an_email_(V2)": {
                "inputs": {
                    "body": {
                        "Body": "<p>@{body('Create_HTML_table')}</p>",
                        "Importance": "Normal",
                        "Subject": "HTML Table",
                        "To": "[email protected]"
                    },
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['office365']['connectionId']"
                        }
                    },
                    "method": "post",
                    "path": "/v2/Mail"
                },
                "runAfter": {
                    "Create_HTML_table": [
                        "Succeeded"
                    ]
                },
                "type": "ApiConnection"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "office365": {
                    "connectionId": "/subscriptions/<SubId>/resourceGroups/<RG>/providers/Microsoft.Web/connections/office365",
                    "connectionName": "office365",
                    "id": "/subscriptions/<SubId>/providers/Microsoft.Web/locations/centralus/managedApis/office365"
                }
            }
        }
    }
}
  • Related