4

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\"}"
}
Hooch
  • 28,817
  • 29
  • 102
  • 161
  • Hi,any progress here with your issue? – Jay Gong Nov 26 '19 at 08:25
  • 2
    @JayGong there is bug in ADF Expression editor. When I put exactly the same expression directly into "body" field without using expression editor it works. So it turns out there is error in ADF expression editor. – Hooch Nov 27 '19 at 10:45
  • ok,i tried to summarize your statement in the answer,if you don't mind, would you please accept it to end this case?thx. – Jay Gong Nov 28 '19 at 01:35

2 Answers2

1

You could get some clues from my previous case:Error "BadRequest" when calling Azure Function in ADF.

The solution is using @json() and @concat() in dynamic content.For you, the entire data may looks like:

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

Just for summary:

It turns out there is error in ADF expression editor because when @Hooch put exactly the same expression directly into "body" field without using expression editor it works.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32
0

I had a similar issue and I've solved it using the JSON escape method discussed at How should I escape strings in JSON?.

In your case my ADF expression would looks like

{
  "test": "Test1",
  "data": "@{replace(replace(activity('Upload SKU').output, '\', '\\'), '"','\"')}"
}
anth0ny-x
  • 46
  • 2