Forum Discussion

KBD's avatar
KBD
Helper III
4 months ago
Solved

Data Factory adding extra \ in JSON data

Hello:   In Azure Data Factory, I am working with JSON data in order to send a request to an Azure function. I need to create the Body of an HTML request that contains properly formatted  JSON th...
  • arabalca's avatar
    arabalca
    4 months ago

    Hi KBD 

    Great to see the _fixed fields are being generated correctly β€” looks like it's already working!

    One question: how are you seeing the backslashes in the result? Is it in the ADF monitor output panel, when you click on the activity during a debug run?

    I ask because that panel serializes everything as JSON, and any quotes inside a string will always show as \". That doesn't necessarily mean the backslashes are actually in the data.

    To confirm, try this:

    1. In the ADF monitor, click the glasses icon on the activity output. If the "Response" value appears as a string wrapped in quotes, the backslashes are just visual representation.

    2. If your function is in Python, add a logging.info() to dump the RAW body it receives and check it in Azure Portal β†’ Function App β†’ Monitor. That will show you what actually arrived, without ADF monitor interference.

    3. Quickest check: if req.get_json() didn't throw any exception and the _fixed fields are correct, the JSON arrived clean.

     

    (Apologies for not going into more detail β€” I'm on my phone and it's a bit tricky to type πŸ˜…)

    Given that your _fixed fields have the right content, you've most likely already solved it without realising it 

     

    If my comments helped solve your question, it would be great if you could like the two comments and mark it as the accepted solution. It helps others with the same issue and also motivates me to keep contributing.

     

    Thanks a lot, I really appreciate it.

     

    AI was used to ensure clarity of wording

  • arabalca's avatar
    arabalca
    4 months ago

    Hi KBD 

     

    Just to clarify β€” I wasn't stating anything, I was asking to better understand what was happening. Thanks for sharing the file, it really helps!

     

    I'm trying to figure this out alongside you while giving you options, so take this as ideas to try rather than definitive answers.

     

    On the backslashes in the file β€” try this: the reason they appear might simply be that the Copy Data activity is writing the response as a text column inside a CSV. CSV format wraps string values in outer quotes and escapes the inner ones as \". That wouldn't be an ADF bug or a problem with your code β€” it would be the output format itself.

     

    On why Python processed correctly despite the backslashes β€” that makes sense: Python received the clean JSON directly from the request, before ADF serialized it to write it into the CSV. That's why the _fixed fields are correct. The problem would be downstream, in how the output is being written.

     

    For Power BI you need a clean .json file.

    If your function is in Python, I think that the cleanest option would be to write the JSON file directly from the function itself, without going through Copy Data. To verify it first, add a logging.info() to dump the RAW body before any processing β€” you can check it in Azure Portal β†’ Function App β†’ Monitor β†’ Invocations. Here's the official reference: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#logging 

     

    If my comments helped solve your question, it would be great if you could like the two comments and mark it as the accepted solution. It helps others with the same issue and also motivates me to keep contributing.

     

    Thanks a lot, I really appreciate it.

     

    AI was used to ensure clarity of wording