Welcome to Microsoft Q&A platform and thanks for posting your question.
Flattening nested JSON data in Azure Data Factory (ADF) Data Flow can be achieved using the flatten transformation. Let’s break down the steps:
Flatten Transformation:
- The flatten transformation is used to take array values inside hierarchical structures (such as JSON) and unroll them into individual rows. This process is known as denormalization.
- You can find the flatten transformation in the mapping data flow within both Azure Data Factory and Azure Synapse Pipelines.
- It allows you to unroll arrays and create one row per item in each array.
- You can find the flatten transformation in the mapping data flow within both Azure Data Factory and Azure Synapse Pipelines.
Configuration:
- The flatten transformation has the following configuration settings:
- Unroll By: Select an array to unroll. The output data will have one row per item in each array. If the unroll-by array in the input row is null or empty, there will be one output row with unrolled values as null.
- You can unroll more than one array per flatten transformation by clicking the plus (+) button.
- You can use ADF data flow meta functions (such as name and type) and pattern matching to unroll arrays that match specific criteria.
- When including multiple arrays in a single flatten transformation, the results will be a cartesian product of all possible array values.
- Unroll Root: By default, the flatten transformation unrolls an array to the top of the hierarchy it exists in. Optionally, you can select an array as your unroll root. The unroll root must be an array of complex objects that either is or contains the unroll-by array.
- If an unroll root is selected, the output data will contain at least one row per item in the unroll root. Input rows without any items in the unroll root will be dropped from the output data.
- Choosing an unroll root will always output a less than or equal number of rows than the default behavior.
- Flatten Mapping: Similar to the select transformation, choose the projection of the new structure from incoming fields and the denormalized array. If a denormalized array is mapped, the output column will be the same data type as the array.
- Rule-Based Mapping: The flatten transformation supports rule-based mapping, allowing you to create dynamic and flexible transformations based on rules and hierarchy levels.
- Example:
- Suppose you have a complex nested JSON structure with sub-arrays. Here’s how you can flatten it:
- Add two source transformations pointing to the same source JSON.
- Select ‘Array of documents’ in the JSON settings for both sources.
- Add flatten transformations to each of the sources.
- For one flatten transformation, select rows [] to unroll by, and for the other one, select columns [ to unroll by
- .Remember to verify your mapping output using the inspect tab and data preview. With these steps, you’ll be able to flatten your nested JSON data efficiently using ADF Data Flow Hope this helps. Do let us know if you any further queries.
If this answers your query, do clickAccept Answer
andYes
for was this answer helpful. And, if you have any further query do let us know.