Azure Data Factory aggregating SQL rows into JSON with path data and values

Cory Seaman 1 Reputation point
2021-10-20T23:47:47.67+00:00

I've seen how to use the Aggregate transformation in an ADF Data Flow along with a static hierarchy specified in a Derived Columns transformation and the collect() function to output custom JSON.

What I want to do is a little different. If my tabular data contains one column with a single attribute value, and another column with a string representing the JSON path where I want the first column's attribute value to be output in the JSON schema, how would this sort of transformation be achieved?

Table Input:
142233-image.png

JSON Output:

{  
 "user": {  
 "id" : 1  
 "firstName": "John",  
 "lastName": "Doe",  
 "address": {  
 "city": "Pittsburgh",  
 "state": "Pennsylvania"  
 }  
 },  
 "user": {  
 "id" : 2  
 "firstName": "Jane",  
 "lastName": "Doe",  
 "address": {  
 "city": "Pittsburgh",  
 "state": "Pennsylvania"  
 }  
 },  
}  
Azure SQL Database
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

1 answer

Sort by: Most helpful
  1. svijay-MSFT 5,256 Reputation points Microsoft Employee Moderator
    2021-10-22T18:15:34.15+00:00

    Hello @Cory Seaman ,

    Thanks for the question and using MS Q&A platform.

    I was able to get this by combining Mappng data flow and Copy Activity. The mapping Data Flow to transform the columns.

    142966-image.png

    For Demonstration purpose,

    I took only the below columns :

    user.name  
    entity  
    user.address.state  
    user.address.city  
    

    Source :

    142965-image.png

    The complete DataFlow :

    142986-image.png

    The first thing I did was the transpose the AttributePath and Attribute Values using Pivot columns

    143051-image.png

    For 1 EntityID - there will be one row of the record.

    The below is the Pivot Configuration I had

    143061-pcgif.gif

    There will be drifted columns generated - I mapped them with Window Schema Modifier. Or you can click on the "Map drifted Columns" in the data preview section of the Pivot Action.

    143042-image.png

    I outputted as a JSON file using a sink transformation

    143062-image.png

    Now with as a source file - output of the Above DataFlow,

    I did copy activity to destination (sink) - as a JSON.

    I imported schema from a sample file - this would be file with output that you had shared in the question,

    143071-image.png

    Now in the Copy activity, you could map the columns as required.

    143043-image.png

    Output :

    142980-image.png

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

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

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. 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
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

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.