Share via

ADF copy activity mapping complete object within array

Robbert-Jan Wijnen 0 Reputation points
2025-07-14T14:34:28.3133333+00:00

I am exploring the possibilities Azure Data Factory has. I am trying to load data from a web api. The result is a JSON:

{
  "comments": [
    {
      "id": 1,
      "body": "This is some awesome thinking!",
      "postId": 242,
      "likes": 3,
      "user": {
        "id": 105,
        "username": "emmac",
        "fullName": "Emma Wilson"
      }
    },
    {
      "id": 2,
      "body": "What terrific math skills you're showing!",
      "postId": 46,
      "likes": 4,
      "user": {
        "id": 183,
        "username": "cameronp",
        "fullName": "Cameron Perez"
      }
    },
    {
      "id": 3,
      "body": "You are an amazing writer!",
      "postId": 235,
      "likes": 2,
      "user": {
        "id": 1,
        "username": "emilys",
        "fullName": "Emily Johnson"
      }
    }
  ],
  "total": 340,
  "skip": 0,
  "limit": 3
}

My table in SQL server has two columns:

  • id
  • json_object

Per comment i want to load the ID in the ID column and the complete json result for that particular comment in the column json_object.

I set my collection reference to: '$['comments']' to loop over each comment. I cannot figure out how to make the mapping for my json_object column. For ID 1 i need the value for the column json_object to be:

{
      "id": 1,
      "body": "This is some awesome thinking!",
      "postId": 242,
      "likes": 3,
      "user": {
        "id": 105,
        "username": "emmac",
        "fullName": "Emma Wilson"
      }
    }

Any suggestions or is this just not possible within the Copy activity?

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Venkat Reddy Navari 5,840 Reputation points Microsoft External Staff Moderator
    2025-07-14T19:57:03.5333333+00:00

    Hi Robbert-Jan Wijnen

    Yes, this scenario is possible within Azure Data Factory's Copy Activity, with a bit of JSON mapping and transformation. Since you want to insert both the id and the entire comment object into your SQL table, here's how you can achieve that:

    Set Collection Reference: You've already done this correctly:

    
    $.comments
    

    Create a Mapping in Copy Activity: Under Mappings, map:

    • idid
    • Use Expression mapping to convert the full comment object to a JSON string for json_object.

    Use Expression Mapping for json_object: Unfortunately, ADF doesn't have a built-in way to directly map the whole object as a JSON string. But you can work around this using a Derived Column transformation (if using Data Flow), or use a custom inline mapping with ADF's Copy Activity if you're using Mapping Data Flows.

    Option A: Use Data Flow

    Add a Derived Column step before the sink.

    Create a new column json_object using the toString() or string() function:

    
    json_object = toString($$)
    

    Here, $$ refers to the current object, so it serializes the whole comment.

    Option B: Preprocess in Azure Function / Logic App (if needed)

    If you're limited to just Copy Activity (without Data Flows), then you'd need to preprocess the source in:

    • Azure Function
    • Logic App
    • or REST API that returns json_object as a string field per record.

    Alternative: Use Copy Activity with REST + Sink Stored Procedure

    If using only Copy Activity, you can write a Stored Procedure as your Sink and pass:

    • id as one column
    • the full JSON row as a string using @activity('YourCopyActivity').output.rows or a similar workaround.

    Hope this helps. If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.