The workflow expression language and content types

With Logic Apps, you can work with multiple content types, such as JSON, XML, Base64, and more. Logic Apps has built-in functions that are used within workflow expressions for conversion, transformation, and translation. For example, you can convert strings such as JSON and XML to @json() and @xml() workflow function expressions.

The following table displays the various content types along with casting types. You can also combine these content type functions to translate messages in your desired format:

Function

Cast operations

json()

Translates data to application/JSON

xml()

Translates data to application/XML

binary()

Translates data to application/octet-stream

string()

Translates data to text/plain

decodeDataUri()

Decodes a dataUri into a byte array

base64toString()

Converts a Base64-encoded string to text/plain

base64toBinary()

Converts a Base64-encoded string to application/octet-stream

base64()

Converts content to a Base64 string

encodeDataUri()

Encodes a string as a dataUri byte array

 

In the following example, we've used an HTTP request trigger to get the JSON request, and throughout the workflow, we've converted the request message into various content types before sending the same response back:

In the following code view, we can list various functions that are used together for content type modification:

When working with Logic Apps, it is also critical to understand how you can deal with NULL values in the request data. There are three different ways to gracefully handle NULL reference exceptions in Logic Apps:

  1. Stringify character: The first option is to use a {} stringify character in the Logic Apps expression language; for example, changing your Logic Apps expression language expression from default to the {} stringify format is done as follows:

The execution of the Logic Apps expression will handle the NULL-to-string conversion, as displayed in the following screenshot:

  1. Parse JSON: The second option is to use the Parse JSON action with an array of the content type (for example, string, null) instead of the default. With this, any request data coming through action or trigger will have a valid content type:

  1. Coalesce functionWhen working with a Logic Apps conditional statement, you should use the coalesce function, which can help you to deal with NULL reference exceptions. The following example displays a conditional statement with the coalesce function:
"@equals(coalesce(triggerBody()?.description, 'nullcheck'), 'nullcheck')
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.214.32