ADF Copy Data JSON Source dynamic schema mapping

Mav 81 Reputation points
2022-01-27T08:33:23.507+00:00

Hi
I am working on ADF Copy data activity. HTTP Dataset is returning a JSON with the following sample JSON output

{
"totalRowCount": 1,
"data": [
{
"ProductCode": "P - 1",
"ProductType": "CARS",
"fields": [
{
"fieldName": "CarType",
"label": "Is this an electric car?",
"dataTypeName": "RADIOBUTTON",
"fields": null,
"values": [
{
"value": "No"
}
]
},
{
"fieldName": "CarLocation",
"label": "Where is the Vendor located",
"dataTypeName": "SINGLESELECT",
"fields": null,
"values": [
{
"value": "123 NY Park NY City USA"
}
]
}
]
}
]
}

For ADF Copy data activity the dynamic mapping I am providing is this

{"type":"TabularTranslator",
"mappings":[
{"source":{"path":"['ProductCode']"},"sink":{"name":"ProductCode","type":"String"}}
,{"source":{"path":"['ProductType']"},"sink":{"name":"ProductType","type":"String"}}
,{"source":{"path":"['fields'][0]['fieldName']"},"sink":{"name":"fieldName","type":"String"}}
,{"source":{"path":"['fields'][0]['label']"},"sink":{"name":"label","type":"String"}}
,{"source":{"path":"['fields'][0]['dataTypeName']"},"sink":{"name":"dataTypeName","type":"String"}}
,{"source":{"path":"['fields'][0]['values'][0]['value']"},"sink":{"name":"value","type":"String"}}
,{"source":{"path":"['fields'][0]['fields']"},"sink":{"name":"Fields","type":"String"}}]
,"collectionReference":"$['data']"}

However it is copying only first element of the array but I am expecting 2 rows.
What needs to be changed in the mapping .
Thanks in advance as I am new to this

Azure SQL Database
Azure Data Lake Storage
Azure Data Lake Storage
An Azure service that provides an enterprise-wide hyper-scale repository for big data analytic workloads and is integrated with Azure Blob Storage.
1,538 questions
Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,325 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,206 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. svijay-MSFT 5,241 Reputation points Microsoft Employee
    2022-01-27T17:03:02.103+00:00

    Hello @devhere,

    Thanks for the ask and using Microsoft Q&A platform .

    If my understanding is correct you are performing a copy activity from a JSON to sink. You are not able to encountering the issue.

    You are likely to encounter the issue if you are not providing collection reference is incorrect. I looked at the mapping & understood that the collection reference you have provided as data.

    The below would be solution :

    Setting the collection reference as $['data'][0]['fields']

    169113-image.png

    STEPS :

    1. You could clear current mapping.
    2. Enter $['data'][0]['fields'] manually
    3. Click import schemas
    4. Ensure that you are giving data type for mappings.

    169171-savegif.gif

    Output :

    169191-image.png

    Please do let me know how it goes.

    -------------------------------------------------------------------------------------------------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

  2. Mav 81 Reputation points
    2022-01-27T21:45:44.897+00:00

    Another example from my JSON. It can have more than 1 row

    {
    "totalRowCount": 2,
    "data": [
    {
    "ProductCode": "P - 1",
    "ProductType": "CARS",
    "fields": [
    {
    "fieldName": "CarType",
    "label": "Is this an electric car?",
    "dataTypeName": "RADIOBUTTON",
    "fields": null,
    "values": [
    {
    "value": "No"
    }
    ]
    },
    {
    "fieldName": "CarLocation",
    "label": "Where is the Vendor located",
    "dataTypeName": "SINGLESELECT",
    "fields": null,
    "values": [
    {
    "value": "123 NY Park NY City USA"
    }
    ]
    }
    ]
    },
    {
    "ProductCode": "P - 2",
    "ProductType": "BUS",
    "fields": [
    {
    "fieldName": "BusType",
    "label": "Is this an electric Bus?",
    "dataTypeName": "RADIOBUTTON",
    "fields": null,
    "values": [
    {
    "value": "No"
    }
    ]
    },
    {
    "fieldName": "BusLocation",
    "label": "Where is the Vendor located",
    "dataTypeName": "SINGLESELECT",
    "fields": null,
    "values": [
    {
    "value": "4444 NY Park NY City USA"
    }
    ]
    }
    ]
    }
    ]
    }

    0 comments No comments

  3. vishnu 0 Reputation points
    2025-02-03T07:57:28.8533333+00:00

    You have to use just ['fields'] instead of $['data'][0]['fields']

    if it is like $['data'][0][name]['fields'] then use ['name']['fields']

    0 comments No comments

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.