sqljsonazure-data-factorycopy-data

Stop ADF escaping character when creating JSON file from stored procedure


I have a copy data activity that executes a stored procedure, which outputs a query into JSON, using FOR JSON path.

The copy activity then sinks the data to a .json file in a given folder location.

However, when reviewing the file, the double quotes are being escaped with a \ so my JSON isn't valid.

Here's an example;

CREATE PROCEDURE #testJson
AS
    SELECT 'Michael' AS Forename, 'Smith' AS Surname 
    FOR JSON PATH

EXEC #testJson

The output in SQL Server, is as follows;

[ { "Forename": "Michael", "Surname": "Smith" } ]

However, ADF outputs the following:

[{\"Forename\":\"Michael\",\"Surname\":\"Smith\"}]

How can I avoid this when using the copy data activity, as I need to execute a stored procedure to produce my JSON output.

Copy data source:

enter image description here

Sink:

enter image description here

JSON Source Code:

{
    "name": "Copy stored proc to JSON",
    "type": "Copy",
    "dependsOn": [],
    "policy": {
        "timeout": "0.12:00:00",
        "retry": 0,
        "retryIntervalInSeconds": 30,
        "secureOutput": false,
        "secureInput": false
    },
    "userProperties": [],
    "typeProperties": {
        "source": {
            "type": "AzureSqlSource",
            "sqlReaderStoredProcedureName": "#testJson",   
            "queryTimeout": "02:00:00",
            "partitionOption": "None"
        }, 
        "sink": {
            "type": "JsonSink",
            "storeSettings": {
                "type": "AzureBlobStorageWriteSettings"
            },
            "formatSettings": {
                "type": "JsonWriteSettings"
            }
        },
        "enableStaging": false
    },
    "inputs": [
        {
            "referenceName": "DestinationTables",
            "type": "DatasetReference",
            "parameters": {
                "TableSchema": "",
                "TableName": ""
            }
        }  
    ],
    "outputs": [  
        {
            "referenceName": "testJsonOutput",
            "type": "DatasetReference"
        }
    ]
}

Solution

  • enter image description here

    enter image description here

    enter image description here