TJ_
TJ_

Reputation: 647

Map nested JSON in Azure Data Factory to raw object

Since ADF (Azure Data Factory) isn't able to handle complex/nested JSON objects, I'm using OPENJSON in SQL to parse the objects. But, I can't get the 'raw' JSON from the following object:

{
   "rows":[
      {
         "name":"Name1",
         "attribute1":"attribute1",
         "attribute2":"attribute2"
      },
      {
         "name":"Name2",
         "attribute1":"attribute1",
         "attribute2":"attribute2"
      },
      {
         "name":"Name3",
         "attribute1":"attribute1",
         "attribute2":"attribute2"
      }
   ]
}

Config 1

When I use this config: enter image description here

I get all the names listed

  1. Name1
  2. Name2
  3. Name3

Result:

enter image description here

Config 2

When I use this config:

enter image description here

I get the whole JSON in one record:

  1. [ {{full JSON}} ]

Result:

enter image description here

Needed config

But, what I want, is this result:

  1. { "name":"Name1", "attribute1":"attribute1", "attribute2":"attribute2 }
  2. { "name":"Name2", "attribute1":"attribute1", "attribute2":"attribute2 }
  3. { "name":"Name3", "attribute1":"attribute1", "attribute2":"attribute2 }

Result:

enter image description here

So, I need the iteration of Config 1, with the raw JSON per row. Everytime I use the $['rows'], or $['rows'][0], it seems to 'forget' to iterate.

Anyone?

Upvotes: 1

Views: 7226

Answers (2)

Leon Yue
Leon Yue

Reputation: 16431

The copy active can help us achieve it.

For example I copy B.json fron container "backup" to another Blob container "testcontainer" .

This is my B.json source dataset:

enter image description here

Source:

enter image description here

Sink: enter image description here

Mapping:

enter image description here

Pipeline executed successful:

enter image description here

Check the data in testcontainer:

enter image description here

Hope this helps.


Update:

Copy the nested json to SQL.

Source is the same B.json in blob.

Sink dataset:

enter image description here

Sink:

enter image description here

Mapping:

enter image description here

Run pipeline:

enter image description here

Check the data in SQL database:

enter image description here

Upvotes: 0

Mark Kromer MSFT
Mark Kromer MSFT

Reputation: 3838

Have you tried Data Flows to handle JSON structures? We have that feature built-in with data flow transformations like derived column, flatten, and sink mapping.

Upvotes: 0

Related Questions