Function Friday: Data Type Conversion Functions – Arrays, JSON and XML
Tags: development, flow, functionfriday, powerautomate
Published: 2022-08-12 14:31:06

---
title: Function Friday: Data Type Conversion Functions – Arrays, JSON and XML
published: true
date: 2022-08-05 14:00:00 UTC
tags: Development,flow,FunctionFriday,PowerAutomate
canonical_url: https://barretblake.dev/2022/08/function-friday-data-type-conversion-functions-arrays-json-and-xml/?utm_source=rss&utm_medium=rss&utm_campaign=function-friday-data-type-conversion-functions-arrays-json-and-xml
---

This time we’re wrapping up the last of the data type conversion functions. We’ll cover the more complex data types: arrays, JSON, and XML.

## array

The array function creates an array from a single input data element. The format is simple:

```
array('<value>')
```

And as an example:

```
array('hello there') // returns ["hello there"]
```

To be honest, there’s no reason to use the array function. The createArray function allows you to pass in multiple data elements and you get the same result.

## createArray

The createArray works the same way as array, but allows you to pass in multiple input elements, returning them as a single array. The format is as follows:

```
createArray('<value1>', '<value2',...)
```

And here is an example:

```
createArray('hello', 'there') //returns ["hello","there"]
```

As I mentioned above, you should pretty much always use this function instead of array, just for consistency’s sake. As with any array in Power Automate, the values can be of different types.

```
createArray('hello', 25, 'there') // returns ["hello",25,"there"]
```

## json

This function will take your input and return it as a JSON formatted object. The pattern is as follows:

```
json('<value>')
```

The value passed in must be a string or XML. And if you’re passing in XML, you’ll need to pair it with the xml function to parse the XML data so the json function understands it. For example:

```
json(xml('YOUR XML DATA'))
```

This function is most useful for parsing JSON data returned from an API or file so that Power Automate can treat it as a JSON data type instead of treating it as a string.

An example:

```
json('{"obiWanSays": "Hello there!"}') // returns { "obiWanSays": "Hello there!" }
```

If you’re looking to take disparate data elements and build a JSON object from them, take a look at the compose action in Power Automate instead.

## xml

As with the json function, the xml function is used for parsing xml being passed in as a string into an object that Power Automate will understand to be XML. The format is similar to the others:

```
xml('<value>')
```

As with the json function, this will most often be used to parse data returned from an API or a file that is XML in nature. And the data being passed in must be a string or a JSON data object. Also like the json function, if the data being passed in is JSON in a string, it should be paired with that function. Like so:

```
xml(json('<JSON DATA OBJECT>'))
```

This will take the JSON string data, parse the JSON, then convert it into an XML object.

## Conclusion

This wraps up the last of the data type conversion functions. Coming up next I’ll start delving into one of the biggest pain points in Power Automate (and almost any coding environment): date and time.

The post [Function Friday: Data Type Conversion Functions – Arrays, JSON and XML](https://barretblake.dev/2022/08/function-friday-data-type-conversion-functions-arrays-json-and-xml/) first appeared on [Barret Codes](https://barretblake.dev).