Parse json file in U-SQL Parse json file in U-SQL azure azure

Parse json file in U-SQL


This is probably because you have new JSON blocks on each new line of the file. This means you need to parse it slightly differently rather than in being a straight JSON file.

Try just using a text extractor first to bring in each JSON element with a new line delimiter. Like this...

DECLARE @Full_Path string = "etc"@RawExtract =     EXTRACT         [RawString] string,         [FileName] string //optional, see below    FROM        @Full_Path    USING         Extractors.Text(delimiter:'\b', quoting : false);

Then shred the JSON with the assembly you've referenced, but using the JSON tuple method. Like this...

REFERENCE ASSEMBLY [Newtonsoft.Json];REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];@ParsedJSONLines =     SELECT         Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple([RawString]) AS JSONLine,        [FileName]    FROM         @RawExtract

Next, get the values out. Like this...

@StagedData =    SELECT         JSONLine["dimBetType_SKey"] AS dimBetType_SKey,        JSONLine["BetType_BKey"] AS BetType_BKey,        JSONLine["BetTypeName"] AS BetTypeName        [FileName]    FROM         @ParsedJSONLines;

Finally, do your output to CSV, or whatever.

DECLARE @Output_Path string = "etc"OUTPUT @StagedDataTO @Output_Path USING Outputters.Csv();

As a side note, you don't need to reference the complete data lake store path. The analytics engine knows where the root to the storage is so you can probably replace your variables with just this...

DECLARE @Full_Path string = "/2017/03/28/{FileName}";

Hope this helps sort your issue.


For you information, ADF can help you easily copy from JSON(JSON Format) to be CSV(Text Format). Instructions can be referred from:https://docs.microsoft.com/en-us/azure/data-factory/data-factory-faq#specifying-formats

Copy wizard can help you preview the data and set up the pipeline via UI.https://docs.microsoft.com/en-us/azure/data-factory/data-factory-copy-data-wizard-tutorial