Skip to content

Commit 248fe8e

Browse files
authored
Merge pull request #104752 from sidramadoss/patch-62
Update stream-analytics-parsing-json.md
2 parents 91ce0fe + 064cca8 commit 248fe8e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

articles/stream-analytics/stream-analytics-parsing-json.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ SELECT DeviceID, PropertyValue AS Temperature INTO TemperatureOutput FROM Stage0
163163
SELECT DeviceID, PropertyValue AS Humidity INTO HumidityOutput FROM Stage0 WHERE PropertyName = 'Humidity'
164164
```
165165

166+
### Parse JSON record in SQL reference data
167+
When using Azure SQL Database as reference data in your job, it's possible to have a column that has data in JSON format. An example is shown below.
168+
169+
|DeviceID|Data|
170+
|-|-|
171+
|12345|{"key" : "value1"}|
172+
|54321|{"key" : "value2"}|
173+
174+
You can parse the JSON record in the *Data* column by writing a simple JavaScript user-defined function.
175+
176+
```javascript
177+
function parseJson(string) {
178+
return JSON.parse(string);
179+
}
180+
```
181+
182+
You can then create a step in your Stream Analytics query as shown below to access the fields of your JSON records.
183+
184+
```SQL
185+
WITH parseJson as
186+
(
187+
SELECT DeviceID, udf.parseJson(sqlRefInput.Data) as metadata,
188+
FROM sqlRefInput
189+
)
190+
191+
SELECT metadata.key
192+
INTO output
193+
FROM streamInput
194+
JOIN parseJson
195+
ON streamInput.DeviceID = parseJson.DeviceID
196+
```
197+
166198
## Array data types
167199

168200
Array data types are an ordered collection of values. Some typical operations on array values are detailed below. These examples use the functions [GetArrayElement](https://docs.microsoft.com/stream-analytics-query/getarrayelement-azure-stream-analytics), [GetArrayElements](https://docs.microsoft.com/stream-analytics-query/getarrayelements-azure-stream-analytics), [GetArrayLength](https://docs.microsoft.com/stream-analytics-query/getarraylength-azure-stream-analytics), and the [APPLY](https://docs.microsoft.com/stream-analytics-query/apply-azure-stream-analytics) operator.

0 commit comments

Comments
 (0)