Azure Data Factory Copy Activity convert sql string in to jobject

Vijay Rudrasamudram 40 Reputation points
2024-07-12T11:22:21.11+00:00

I have a query from Azure SQL database which returns jsonstring like below and want to insert in to Cosmos db as JSON object (not string)

"{\"type\": \"Point\",\"coordinates\":[4.4468420323932429,45.154212148849346]}"

even though i use the JSON_Query the value is inserted as string in cosmos. Please suggest if there is any way to achieve this in ADF copy activity ( i cannot use Data flow Derived column parse method as Shared Integration runtime is used to connect to source and sink and Dataflow does not allow it)

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,518 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 22,541 Reputation points
    2024-07-12T13:58:54.6866667+00:00

    First, create a stored procedure in your Azure SQL database that parses the JSON string and returns a JSON object :

    
    CREATE PROCEDURE GetJsonObject
    
    AS
    
    BEGIN
    
        DECLARE @jsonString NVARCHAR(MAX)
    
        DECLARE @jsonObject NVARCHAR(MAX)
    
        -- Fetch your JSON string here, for example:
    
        SELECT @jsonString = '{"type": "Point","coordinates":[4.4468420323932429,45.154212148849346]}'
    
        -- Parse the JSON string
    
        SELECT @jsonObject = JSON_QUERY(@jsonString)
    
        -- Return the JSON object
    
        SELECT @jsonObject AS JsonObject
    
    END
    
    

    Then create a new pipeline and add a Copy Data Activity where you call the stored procedure :

    
    EXEC GetJsonObject
    
    

    Then set the sink dataset to your Cosmos DB. In the Mapping tab, ensure that the JSON object is correctly mapped.


0 additional answers

Sort by: Most helpful

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.