Hello @Anonymous
I've converted my original answer to a comment to not confuse the answers. I've managed to recreate the exact same issue you have been experiencing. I have made a version of the logic app which performs 4 actions.
- Get's the value from the event hub (When events are available in Event Hub)
- Initialize Variable
- Parse JSON
Set Variable
I test like this when I am having issues with parsing data and confirming the output. Your version of "Parse JSON" had the trigger body "@triggerBody()"
as the input, however I was noticing that when generating the schema for the entire payload, it was not working as expected. Changing this to just the ContentData "@triggerBody()?['ContentData']",
there were no issues with the parsed data and the variable is set. Once thing I did notice, was that I had to manually change the schema as the property Value "body('Parse_JSON')?['data']?['rsp']?['result']?['sensors'][ ]?['value']"
automatically sets as an integer based on the data you gave me, and it needed to be changed to a number.
Try my code here below. If you struggle with it. Create your logic app with the event hub trigger and then copy the Parse_JSON
from the code:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Set_variable": {
"inputs": {
"name": "nadr",
"value": "@{items('For_each')?['value']}"
},
"runAfter": {},
"type": "SetVariable"
}
},
"foreach": "@body('Parse_JSON')?['data']?['rsp']?['result']?['sensors']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "nadr",
"type": "string"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@triggerBody()?['ContentData']",
"schema": {
"properties": {
"data": {
"properties": {
"insId": {
"type": "string"
},
"msgId": {
"type": "string"
},
"raw": {
"items": {
"properties": {
"confirmation": {
"type": "string"
},
"confirmationTs": {
"type": "string"
},
"request": {
"type": "string"
},
"requestTs": {
"type": "string"
},
"response": {
"type": "string"
},
"responseTs": {
"type": "string"
}
},
"required": [
"request",
"requestTs",
"confirmation",
"confirmationTs",
"response",
"responseTs"
],
"type": "object"
},
"type": "array"
},
"rsp": {
"properties": {
"dpaVal": {
"type": "integer"
},
"hwpId": {
"type": "integer"
},
"nAdr": {
"type": "integer"
},
"rCode": {
"type": "integer"
},
"result": {
"properties": {
"sensorIndexes": {
"items": {
"type": "integer"
},
"type": "array"
},
"sensors": {
"items": {
"properties": {
"breakdown": {
"items": {
"properties": {
"decimalPlaces": {
"type": "integer"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"shortName": {
"type": "string"
},
"type": {
"type": "integer"
},
"unit": {
"type": "string"
},
"value": {
"type": "number"
}
},
"required": [
"id",
"type",
"name",
"shortName",
"unit",
"decimalPlaces",
"value"
],
"type": "object"
},
"type": "array"
},
"decimalPlaces": {
"type": "integer"
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"shortName": {
"type": "string"
},
"type": {
"type": "integer"
},
"unit": {
"type": "string"
},
"value": {
"type": "number"
}
},
"required": [
"id",
"type",
"name",
"shortName",
"value",
"unit",
"decimalPlaces"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
},
"status": {
"type": "integer"
},
"statusStr": {
"type": "string"
}
},
"type": "object"
},
"mType": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_events_are_available_in_Event_Hub": {
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 5
},
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['eventhubs']['connectionId']"
}
},
"method": "get",
"path": "/@{encodeURIComponent('q1309140')}/events/batch/head",
"queries": {
"consumerGroupName": "$Default",
"contentType": "application/json",
"maximumEventsCount": 50
}
},
"recurrence": {
"frequency": "Minute",
"interval": 5
},
"splitOn": "@triggerBody()",
"type": "ApiConnection"
}
}
},
"parameters": {
"$connections": {
"value": {
"eventhubs": {
"connectionId": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/Q1309140/providers/Microsoft.Web/connections/eventhubs",
"connectionName": "eventhubs",
"connectionProperties": {
"authentication": {
"type": "ManagedServiceIdentity"
}
},
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Web/locations/westeurope/managedApis/eventhubs"
}
}
}
}
}