首页 > 解决方案 > How to escape json in dynamic content in ADF V2 in Azure?

问题描述

I'm calling Azure function and I'm building the request body using dynamic content.

This is how I build it:

{
  "test": "Test1",
  "data": "@{activity('Upload SKU').output}"
}

I have problem with the "data" node. @{activity('Upload SKU').output is a json string. So the dynamic content creates "mess". It doesn't escape it.

It creates this:

{
  "test": "Test1",
  "data": "{"a": "1"}"
}

How to escape @{activity('Upload SKU').output so that {"a": "1"} creates {\"a\": \"1\"} so that it can be treated as a string and not as a node under "data".

This is what I want to achieve:

{
  "test": "Test1",
  "data": "{\"a\": \"1\"}"
}

标签: azureazure-data-factoryazure-data-factory-2

解决方案


您可以从我之前的案例中得到一些线索:Error "BadRequest" when calling Azure Function in ADF

解决方案是在动态内容中使用@json()@concat()。对于您来说,整个data可能看起来像:

@json(concat('{"test": "Test1,"data":"',@{activity('Upload SKU').output,'"}'))

仅作总结:

事实证明,ADF 表达式编辑器中存在错误,因为当@Hooch 将完全相同的表达式直接放入“body”字段而不使用表达式编辑器时,它可以工作。


推荐阅读