You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Azure Data Factory将REST API复杂JSON映射到Azure SQL(日期映射)

Mapping Complex AlphaVantage JSON to Azure SQL in Azure Data Factory

Got it, let's tackle this mapping challenge with AlphaVantage's nested JSON in ADF—dynamic date keys are definitely a pain when the default Mapping Designer falls short. Here's a step-by-step approach that works reliably:

1. Use Data Flows Instead of Copy Activity Mapping

The AlphaVantage API returns JSON with dynamic date keys under the Time Series (Daily) object (like "2024-05-20": {...}), which the standard Mapping Designer can't handle natively. Data Flows are built for this kind of nested/dynamic structure processing.

Step 1: Set Up the REST Data Source in Data Flow

  • Create a new Data Flow in your pipeline.
  • Add a Source component, select your REST dataset pointing to the AlphaVantage API endpoint.
  • In the Source settings, under JSON path settings, you can optionally set the root path to $.Time Series (Daily) to focus only on the date-based data (skip the Meta Data section if you don't need it).

Step 2: Flatten the Dynamic Date Keys

Add a Flatten transformation right after the Source:

  • In the Flatten settings, select the column corresponding to Time Series (Daily) (it'll show as an object type).
  • Enable the Unroll by key option—this will convert each dynamic date key into a separate row, generating two new columns:
    • A key column (e.g., key) containing the date string (like 2024-05-20)
    • A value column (e.g., value) containing the nested object with open/high/low/close data

Step 3: Expand the Nested Metric Fields

Add a second Flatten transformation (or use a Select transformation) to unpack the value column:

  • For the Flatten option: Select the value object column, then check all the nested fields (like 1. open, 2. high) to turn them into individual columns.
  • Rename these columns to match your Azure SQL table's schema (e.g., rename 1. open to OpenPrice).

Step 4: Convert the Date String to a Date Type

Add a Derived Column transformation to fix the date field:

  • Create a new column (e.g., TradeDate) with the expression:
    toDate(key, 'yyyy-MM-dd')
    
  • This converts the string date from the key column into a proper date type that can map directly to your SQL table's date column.

2. Map to Azure SQL Sink

  • Add a Sink component to the Data Flow, connect it to your Azure SQL dataset.
  • Go to the Mapping tab—you'll now see all your processed columns (including the converted TradeDate) ready to map to your SQL table's columns. Just match each column to the corresponding SQL field, and you're set.

Alternative: If You Prefer Using Copy Activity (Less Efficient)

If you don't want to use Data Flows, you can combine Lookup + ForEach activities, but it's more cumbersome:

  • Use a Lookup Activity to fetch the full JSON response from the API.
  • Use a ForEach Activity to iterate over the Time Series (Daily) object's keys.
  • Inside the ForEach, use a Copy Activity or Stored Procedure Activity to insert each date's data into SQL, parsing the date key and metrics manually via expressions.

But honestly, Data Flows are the cleaner, scalable solution here.

内容的提问来源于stack exchange,提问作者Luis Valencia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 17:28:12