My JSON gets serialized in a string - Logic Apps
Solution ·Azure Logic Apps is a powerful tool.
It takes care of long running tasks, retries, bunch of integrations, etc . .
It also handles JSON payloads natively. JSON flows in and out of an app.
I recently faced a bit of a problem with JSON though.
My JSON was appearing serialized within a string. It took me precious minutes to find out why, so I thought I would share this over here.
I had that error while copy-pasting pieces of ARM template code around my Logic App. This isn’t a designer only common mistake.
Deploying example
Let’s deploy an example:
The deployment is trivial as there is no parameters.
It should deploy one Logic Apps named serialization-sample.
The problem
Let’s simply run the sample app. We can look at the result:
We can see that the resulting JSON payload has two properties:
- serialized has a serialized representation of the JSON payload produced by the previous task
- native has a "native" representation of the JSON payload
Typically, we do not want a serialized representation.
The reason
Because this sample focus on that problem, it might look obvious, but in the middle of a complicated app, it is harder to find.
If we look at the use-json task definition, we’ll have a hint:
We see that the serialized value is within quote while the native one isn’t.
This is confirmed by looking the ARM Template:
"use-json": {
"type": "Compose",
"inputs": {
"serialized": "@{outputs('compose-some-json')}",
"native": "@outputs('compose-some-json')"
},
"runAfter": {
"compose-some-json": [
"Succeeded"
]
}
}
The serialized version has curly braces (i.e. {}) around the output while the native one doesn’t.
That’s it. Subtle problem but one that can waste the best part of an hour to find when not isolated.
Summary
I hope this quick common error scenario is useful.
I wasted about 30 minutes to find that error. Hopefully you won’t have to.