Problem with parsing data from a JSON field

Dragan Antanasković 0 Reputation points

I'm trying to process the log files with the following structure per record:


This is a single record from the log file. As seen from this sample, the record contains the JSON field named "variables", and it is a JSON array. I need to extract certain values from this array. I have first tried with a Javascript UDF, but when I try to test this query, I'm getting the following error:

SyntaxError: JSON.parse Error: Invalid character at position:2 at ExtractValueFromVariables (Unknown script code:8:9)

My Javascript code in the UDF is correct, as it works flawlessly when I run it in a Javascript emulator with sample data. I can send it if someone wants to check it.

I have also tried the SQL function OPENJSON, but it seems it doesn't work in an Azure Stream Analytics job. Can anybody tell me what I need to do?

Azure Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
339 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Gowtham CP 3,340 Reputation points

    Hello Dragan Antanasković ,

    Thank you for reaching out on Microsoft Q&A.

    To extract values from the variables JSON array in Azure Stream Analytics, you can use the GetArrayElements function with CROSS APPLY. This method efficiently handles the array and avoids the need for a JavaScript UDF.

    Sample Query

      v.Name AS variableName,
      v.Value AS variableValue,
    FROM YourInput
    CROSS APPLY GetArrayElements(variables) AS v
    • GetArrayElements: Breaks down the variables array into individual elements.
    • CROSS APPLY: Joins the input stream with the elements of the variables array, allowing access to Name and Value.

    If you found this solution helpful, consider accepting it.

    1 person found this answer helpful.