简体   繁体   中英

Azure Stream Analytics Querying JSON

I have a problem writing a query to extract a table out of the arrays from a json file: The problem is how to get the information of the array “clientPerformance” and then make them all in a normal sql table.

The file looks like this:

"clientPerformance":[  
        {  
         "name":"opportunity",
         "clientProcess":{  
            "value":3620000.0,
            "count":1.0,
            "min":3620000.0,
            "max":3620000.0,
            "stdDev":0.0,
            "sampledValue":3620000.0
         },
         "networkConnection":{  
            "value":10000.0,
            "count":1.0,
            "min":10000.0,
            "max":10000.0,
            "stdDev":0.0,
            "sampledValue":10000.0
         },
         "receiveRequest":{  
            "value":9470000.0,
            "count":1.0,
            "min":9470000.0,
            "max":9470000.0,
            "stdDev":0.0,
            "sampledValue":9470000.0
         },
         "sendRequest":{  
            "value":1400000.0,
            "count":1.0,
            "min":1400000.0,
            "max":1400000.0,
            "stdDev":0.0,
            "sampledValue":1400000.0
         },
         "total":{  
            "value":14500000.0,
            "count":1.0,
            "min":14500000.0,
            "max":14500000.0,
            "stdDev":0.0,
            "sampledValue":14500000.0
         },
         "url":"https://xxxx",
         "urlData":{  
            "base":"/main.aspx",
            "host":"xxxx",
            "hashTag":"",
            "protocol":"https"
         }
      }
   ]

I tried to use Get array elements method and other ways but I am never able to access to clientProcess, networkConnection.. elements

I tried to use for exampls this one:

Select 
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 1), 'clientProcess.count') AS clientProcessCount,
FROM [app-insights-blob-dev] Input 

I would appreciate any help :)

I slightly edited your query to return the clientProcessCount. (I changed the array index from 1 to 0). Also make sure your JSON object starts with { and ends with }.

Select
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'name') AS Name,
GetRecordPropertyValue(GetArrayElement(Input.clientPerformance, 0), 'clientProcess.count') AS clientProcessCount
FROM [app-insights-blob-dev] Input

For other examples to query complex objects with ASA, don't hesitate to look at this blog post .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM