Reputation: 11621
I have a JSON input that looks like
{
"sessionId": 1234,
"deviceId": "MAC:1234",
"IoTHub": {
"MessageId": "1234-1234-1234-1234"
}
}
How can I extract the values of sessionId
, deviceId
and MessageId
in a Azure Datalake Analytics usql script?
Upvotes: 1
Views: 638
Reputation: 11621
.\Examples\DataFormats\Microsoft.Analytics.Samples.sln
.\Examples\DataFormats\Microsoft.Analytics.Samples.Formats\bin\Debug\Microsoft.Analytics.Samples.Formats.dll
.\Examples\DataFormats\Microsoft.Analytics.Samples.Formats\bin\Debug\Newtonsoft.Json.dll
.\assemblies
)
.\lib\...
)Cloud Explorer
, navigate to the ADLA Database -> Assemblies -> right click and register the assemblies
[2] GitHub Azure USQL DataFormats
[3] U-SQL - Extract data from json-array
DECLARE @localDevelopment bool = true;
IF @localDevelopment == true THEN
DROP ASSEMBLY IF EXISTS [Newtonsoft.Json];
DROP ASSEMBLY IF EXISTS [Microsoft.Analytics.Samples.Formats];
CREATE ASSEMBLY [Newtonsoft.Json] FROM @"/lib/Newtonsoft.Json.dll";
CREATE ASSEMBLY [Microsoft.Analytics.Samples.Formats] FROM @"/lib/Microsoft.Analytics.Samples.Formats.dll";
DECLARE @input string = @"/data/input.json";
DECLARE @output string = @"/data/output.csv";
ELSE
DECLARE @input string = @"/data/input.json";
DECLARE @output string = @"/data/output.csv";
END;
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
//Define schema of file, must map all columns
//Names must match keys
@extractDataFirstLevel =
EXTRACT sessionId int,
deviceId string,
IoTHub string
//Date DateTime
FROM @input
USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();
@selectData =
SELECT sessionId,
deviceId,
Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple(IoTHub)["MessageId"] AS messageId
FROM @extractDataFirstLevel;
OUTPUT @selectData
TO @output
USING Outputters.Csv();
Upvotes: 1