Azure Stream Analytics查询结果转JSON传入Azure Function方法问询
Convert Stream Analytics Query Results to JSON for Azure Function
Got it, let's get your Stream Analytics results into JSON format before sending them to your Azure Function. Here are two reliable ways to do this:
1. Adjust Output Serialization Settings (Simplest Approach)
If you just need each record serialized as a standard JSON object, you don't even need to modify your query—just tweak the output configuration for your Azure Function target:
- Go to your Azure Stream Analytics job, navigate to the Outputs tab.
- Select your
fsSMSemailAPPoutput (the Azure Function). - In the serialization settings:
- Set Serialization format to
JSON. - Choose between Line separated (each record is a standalone JSON object on its own line) or Array (all records wrapped in a JSON array) based on what your Azure Function expects.
- Set Serialization format to
- Save the settings, restart your Stream Analytics job, and your results will now be sent as JSON directly to the function.
2. Manually Construct Custom JSON in Your Query
If you need full control over the JSON structure (like custom field names or nested objects), you can build the JSON string directly in your query using Stream Analytics' built-in functions:
SELECT CONCAT( '{', '"Asset_Key": "', STRING_ESCAPE(i1.Asset_Key, 'json'), '",', '"Online": 0,', '"Last_Updated_UTC": "', STRING_ESCAPE(i1.eventenqueuedutctime, 'json'), '",', '"Latest_Record_Date": "', STRING_ESCAPE(i1.eventenqueuedutctime, 'json'), '"', '}' ) AS JsonPayload INTO fsSMSemailAPP FROM YourInputStream i1 -- Replace with your actual input alias
STRING_ESCAPEensures any special characters (like quotes or backslashes) in your data are properly escaped to avoid invalid JSON.- The
CONCATfunction stitches together the JSON structure piece by piece. - Your Azure Function will receive the
JsonPayloadfield containing the complete JSON string for each record.
Either of these methods should solve your problem—start with the first one if you don't need custom JSON, since it's the quickest setup.
内容的提问来源于stack exchange,提问作者RSH
相关产品推荐
相关产品推荐

