How to send a JSON object instead of an array from Azure Data Factory REST Sink

Kingsley Leighton 20 Reputation points
2024-11-22T16:36:43.9966667+00:00

I have a pipeline in Azure Data Factory that has a Copy data Activity with an Azure blob storage source(contains JSON files which each have a single JSON object) and a REST sink. I am sending a PUT request and the API endpoint I am sending the request to expects a JSON object, not an array. I cannot change what the API expects.

On the Microsoft learn page for data factory, REST as Sink https://learn.microsoft.com/en-us/azure/data-factory/connector-rest?tabs=data-factory#rest-as-sink it specifies that the JSON will be sent with the following format:

[
    { <data object> },
    { <data object> },
    ...
]

Is there any way to change the settings or customize the REST sink so it sends the JSON in the below format instead? Or another connector that would be better suited to this?

{ <data object> }

NOTE:
When I have tested this with one file it still sends in array format, just with one element:

[
	{ <data object> }
]
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
{count} votes

Answer accepted by question author
  1. Chandra Boorla 15,455 Reputation points Microsoft External Staff Moderator
    2024-12-05T01:56:45.5866667+00:00

    @Kingsley Leighton

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Issue:

    I have a pipeline in Azure Data Factory that has a Copy data Activity with an Azure blob storage source(contains JSON files which each have a single JSON object) and a REST sink. I am sending a PUT request and the API endpoint I am sending the request to expects a JSON object, not an array. I cannot change what the API expects.

    On the Microsoft learn page for data factory, REST as Sink https://learn.microsoft.com/en-us/azure/data-factory/connector-rest?tabs=data-factory#rest-as-sink it specifies that the JSON will be sent with the following format:

    [
        { <data object> },
        { <data object> },
        ...
    ]
    

    Is there any way to change the settings or customize the REST sink so it sends the JSON in the below format instead? Or another connector that would be better suited to this?

    { <data object> }
    

    NOTE: When I have tested this with one file it still sends in array format, just with one element:

    [
    	{ <data object> }
    ]
    

    Solution:

    I have found a way using a Lookup Activity and a Web Activity. Use a Lookup activity to grab a single or multiple JSON file(s) from the Blob Storage, this will be the output of the Lookup activity. A Web Activity can then be triggered after the completion of the Lookup Activity. In the Web Activity you must specify the body of the message, in which you can use dynamic content to insert the output of the Lookup activity like so:

    @activity('Lookup Product IFP').output.firstRow
    

    This will grab the first JSON object found from the Lookup Activity (firstRow), thus only the JSON object will be sent as the body rather than an array of JSON objects.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    Hope this helps. Do let us know if you have any further queries.


    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.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jose Martinez 0 Reputation points
    2025-09-25T16:00:24.3966667+00:00

    Hi both,

    I was having the same issue as @Kingsley Leighton and I eventually found out that the approach of using a LookUp + Web activities helped. However, I hit a limitation recently in the LookUp activity when I was trying to read the content of a particularly big JSON (a few MBs). The LookUp failed in this case with this error:

    ErrorCode=UserErrorComputePluginFailure,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The size of lookup activity result exceeds the limitation 4194304.,Source=,''Type=Microsoft.DataTransfer.Execution.Core.ExecutionException,Message=The size of lookup activity result exceeds the limitation 4194304.,Source=Microsoft.DataTransfer.TransferTask,'

    Is there any way to overcome this, @Chandra Boorla ? Did you ever face this @Kingsley Leighton ? If yes, how did you solve the issue?

    Thank you both in advance.

    0 comments No comments

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.