0 votes
1 view
in Azure by (17.6k points)

I'm trying to parse below the JSON file using USQL but keep getting an error.

Json [email protected]




Below is the USQL script, I'm trying to extract the data from the above file. 

 REFERENCE ASSEMBLY [Newtonsoft.Json];

    REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];

DECLARE @Full_Path string =


DECLARE @Output_Path = "adl://xxxx.azuredatalakestore.net/Output/Output.csv";

@logSchema =

EXTRACT dimBetType_SKey int

FROM @Full_Path

USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor();

OUTPUT @logSchema

TO @Output_Path 

USING Outputters.Csv();

 But the USQL keeps failing with Vertex error

Any help?

1 Answer

0 votes
by (47.2k points)
  • As you have new JSON blocks on each new line of the file, you need to parse it in a different manner rather than a straight JSON file

  • You can make use of text extractor to bring a new  line delimiter in each JSON element in the following way

DECLARE @Full_Path string = "etc"

@RawExtract = 


        [RawString] string, 

        [FileName] string //optional, see below




        Extractors.Text(delimiter:'\b', quoting : false);

  • Later you need to shred the JSON with the assembly which you have referenced, by using the JSON tuple method in the following way:


REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];

@ParsedJSONLines = 


        Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple([RawString]) AS JSONLine,




  • Then you will get the values in this way:

@StagedData =


        JSONLine["dimBetType_SKey"] AS dimBetType_SKey,

        JSONLine["BetType_BKey"] AS BetType_BKey,

        JSONLine["BetTypeName"] AS BetTypeName




  • Finally, format your output to CSV or any other

DECLARE @Output_Path string = "etc"

OUTPUT @StagedData

TO @Output_Path 

USING Outputters.Csv();

  • You don't need to refer the complete data lake store path as the analytic engine already know the path of the root storage so you can replace the variables in this way

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !