How to Flatten Nested Time-Series JSON from API into Azure SQL using ADF Mapping Data Flow?

YERNAIDU SIRAPARAPU 45 Reputation points
2025-05-24T09:59:17.5933333+00:00

How to Flatten Nested Time-Series JSON from API into Azure SQL using ADF Mapping Data Flow?

Hi Community,

I'm trying to extract and load data from API returning the following JSON format into an Azure SQL table using Azure Data Factory.

{ "2023-07-30": [], "2023-07-31": [], "2023-08-01": [ { "breakdown": "email", "contacts": 2, "customers": 2 } ], "2023-08-02": [], "2023-08-03": [ { "breakdown": "direct", "contacts": 5, "customers": 1 }, { "breakdown": "referral", "contacts": 3, "customers": 0 } ], "2023-08-04": [], "2023-09-01": [ { "breakdown": "direct", "contacts": 76, "customers": 40 } ], "2023-09-02": [], "2023-09-03": [] }

Goal: I want to flatten this nested structure and load it into Azure SQL like this:

Report Date Breakdown Contacts Customers
2023-07-30 (no row) (no row) (no row)
2023-07-31 (no row) (no row) (no row)
2023-08-01 email 2 2
2023-08-02 (no row) (no row) (no row)
2023-08-03 direct 5 1
2023-08-03 referral 3 0
2023-08-04 (no row) (no row) (no row)
2023-09-01 direct 76 40
2023-09-02 (no row) (no row) (no row)
2023-09-03 (no row) (no row) (no row)
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Burlachenko 9,780 Reputation points
    2025-05-26T07:53:31.7566667+00:00

    Hey Yernaidu,

    Thanks for posting your question on the Q&A portal! I see you're working with a nested time-series JSON and trying to flatten it in Azure Data Factory mapping data flow before loading it into Azure SQL. Let me walk you through how to do this step by step in a simple way.

    First, in your data flow, you'll need to use the flatten transformation to handle the nested arrays. Since your JSON has dates as keys and arrays of objects as values, we'll need to first convert this structure into rows.

    Source setup: In your source dataset, make sure you're reading the JSON file or API response correctly. Set the JSON file path or API endpoint, and ensure the format is set to JSON. You can check the microsoft documentation on JSON datasets in ADF here.

    Flatten transformation: After the source, add a flatten transformation. Here, you'll want to unroll the nested arrays under each date. Since your dates are dynamic keys, you might need to use a derived column first to normalize the structure. For example, you can use an expression to convert the date keys into a column like reportDate and then unroll the arrays. The flatten transformation docs are here.

    Handling empty arrays: For dates with empty arrays (like "2023-07-30": []), you can use a conditional split to either keep them as-is or filter them out. If you want to keep them (as shown in your goal), you might need to add a derived column to mark them before splitting.

    Mapping fields: Once flattened, map the fields (breakdown, contacts, customers) to your Azure SQL table columns. If a date has no entries, you can use a select transformation to ensure those rows still appear with null values.

    Sink to Azure SQL: Finally, configure your sink to write to Azure SQL. Make sure the table structure matches your output (reportDate, breakdown, contacts, customers). The ADF SQL sink docs are here.

    A quick tip, if the JSON structure is tricky, you might want to use a data flow script or pre-processing with a web activity to reshape it before the data flow.

    Hope this helps!

    Best regards,
    Alex
    P.S. If my answer help to you, please Accept my answer
    PPS That is my Answer and not a Comment
    https://ctrlaltdel.blog/
    

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.