I want to store the below JSON data to the Azure table. Here the input and the output for Azure Stream Analytics are Azure IoT Hub and table respectively.
[
{
"device1": [
{
"name": "temperature",
"value": 50
},
"name": "voltage",
"value": 220
}
],
"device2": [
{
"name": "temperature",
"value": 10
},
"name": "voltage",
"value": 200
}
]
}
]
final result would look like below image
I tried with simple json formate
[{
"messageId": messageId,
"name": "temperature"
}]
SELECT
i.messageId AS messageId,
i.name AS name,
i.PartitionId,
i.EventProcessedUtcTime,
i.EventEnqueuedUtcTime
INTO
[table]
FROM
[input] i
But for nested and dynamic key data i am confused.
2
Answers
Here’s how you can flatten the JSON data and insert it into an Azure table using C# and Azure Table Storage SDK:
Replace "your-account-name", "your-account-key", and "YourTableName" with your Azure Storage account credentials and the name of your Azure Table.
For your case, you can use cross apply and getarrayelements to get each element of the array into a separate row.
Below is the similar sample Json, I tried with:
Azure Stream analytics query to flatten this Json array:
Output: