My JSON gets serialized in a string – Logic Apps


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.

Code is on GitHub.

Deploying example

Let’s deploy an example:

Deploy button

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:

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:

Use json

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.


One thought on “My JSON gets serialized in a string – Logic Apps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s