JSON source in ADF

Nagesh CL 696 Reputation points
2021-08-27T10:45:24.593+00:00

Hi Team,

I have a source which is a azure sql DB. The output from that source is JSON. Query and sample output is as below: -

SELECT * FROM dbo.SalesHeader SH
INNER JOIN dbo.SalesDetail SD ON SH.SalesOrderID = SD.SalesOrderID
FOR JSON AUTO

127018-image.png

The issue is, when i place this sql as source query in ADF mapping data flow, i get an error as below:-

127141-image.png

How to resolve this issue? How to get the JSON output in a single column? Single row per SalesOrderID and the JSON structure in a single column?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. ShaikMaheer-MSFT 38,546 Reputation points Microsoft Employee Moderator
    2021-08-30T07:22:27.12+00:00

    Hi @Nagesh CL ,

    Thank you for posting query in Microsoft Q&A Platform.

    Yes unfortunately using "FOR JSON AUTO" sql query directly in Mapping data flows ends with this error.

    You may consider below work around to avoid these error.

    Use the query in lookup activity, and pass your json data string to data flow parameter. You need to have a parameter created inside your data flow. Use derived column transformation to generate new column on top of your data and save these parameter as value in to that column.

    Below is detailed implementation of same.

    Step1: Lookup activity to run your query of "FOR JSON AUTO"
    code used:

    DECLARE @json NVARCHAR(MAX);  
    SET @json=(select * from dbo.tbl_employees FOR JSON AUTO);  
    SELECT @json as JsonData;  
    

    127414-lookup.gif

    Step2: Pass lookup activity output to dataflow parameter
    pipeline expression used: @activity('Lookup1').output.firstRow.JsonData
    127449-image.png

    Step3: Source Transformation which points to some dummy file with single column and single row data and parameter created inside data flow.
    127415-sourcetransformation.gif

    Step4: Derived Column transformation to add new column with data flow parameter as value. So that you can get or json as value inside new column.
    127417-derviedcolumn.gif

    Once above steps done, you can use select transformation to get only your jsonData column.

    Hope this will help. Please let us know if any further queries. Thank you.

    -----------------------

    • Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification.
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.