# JSON functions

This page describes the additional set of predefined Jsonnet functions for the [Data Transformer Script](https://docs.cloud.google.com/application-integration/docs/configure-data-transformer-script-task.md.txt) task available in Application Integration.

### Before you begin


To use the following predefined functions, you must import the `functions` library in your script. Importing the `functions` library lets you use both the standard Jsonnet functions and the predefined **Data Transformer** functions.


Application Integration supports Jsonnet functions library v0.20.0. For information about the Jsonnet standard functions, see [Jsonnet Standard Library](https://jsonnet.org/ref/stdlib.html).

*** ** * ** ***

### `Manifest XML`

| Syntax | ```html manifestXml(json, format = "FORMAT", indent_output = false) ``` |
| Description | Converts the specified input JSON object into an XML string. |
| Input parameter | **json:** The input JSON object. **format:** The input JSON representation format. Replace <var translate="no">FORMAT</var> with one of the following supported formats: - `badgerfish` (default): Use the [BadgerFish](http://www.sklar.com/badgerfish) format to map JSON fields to XML in a key-value manner. - `jsonml`: Use the [JsonML](https://en.wikipedia.org/wiki/JsonML) format when maintaining element order is important for your integration, as it represents XML elements as arrays and preserves their original ordering. **Example usage:** ```html manifestXml(jsonObject, "badgerfish", false) [or] manifestXml(jsonArray, "jsonml", false) ``` **indent_output:** Boolean input to indicate if the output XML string should be indented. Default value is `False`. |
| Return type | `STRING` |
| Output | Returns the XML string of the provided JSON object representation. |
|---|---|

*** ** * ** ***

### `Object Remove Key`

| Syntax | ```html objectRemoveKey(obj, key) ``` |
| Description | Removes a property from a JSON object. |
| Input parameter | **obj:** The input JSON object. **key:** The JSON property to remove. |
| Return type | `JSON` |
| Output | Updated JSON object after removing the specified property and its corresponding value. |
|---|---|

*** ** * ** ***

### `Parse XML`

| Syntax | ```html parseXml(xml, format = "badgerfish") ``` |
| Description | Parses the specified input XML string into a JSON object. |
| Input parameter | **xml:** The input XML string. **format:** The output JSON representation format. > [!NOTE] > **Note:** The default JSON representation format used is [BadgerFish](http://www.sklar.com/badgerfish/). The **parseXml()** function currently only supports *BadgerFish* format. <br /> |
| Return type | `JSON` |
| Output | Returns the JSON object representation of the provided XML string. |
|---|---|

*** ** * ** ***

### `Parse CSV With Header`

| Syntax | ```html parseCsvWithHeader(input, delimiter = ",", overwrite_duplicate_headers = true) ``` |
| Description | Parse given input csv string as json. The first row would be considered as header. For example, `f.parseCsvWithHeader("index,product,company\n1,Application Integration,Google\n2,Pubsub,Google")` would generate `[{"index": "1", "product": "Application Integration", "company": "Google"},{"index": "2", "product": "Pubsub", "company": "Google"}]`. |
| Input parameter | **input:** The CSV string to be parsed. **delimiter:** Delimiter string to be used. Default value is ','. **overwrite_duplicate_headers:** Option to overwrite values for the duplicate headers. If set to false, duplicate header would be renamed. Default value is `true`. |
| Return type | `JSON` |
| Output | Returns the json representation of given csv string. |
|---|---|

*** ** * ** ***

### `Manifest CSV`

| Syntax | ```html manifestCsv(json, headers = null) ``` |
| Description | Convert given json into csv string. For example, `f.manifestCsv([{"index": "1", "product": "Application Integration", "company": "Google"},{"index": "2", "product": "Pubsub", "company": "Google"}])` would generate `index,product,company\n1,Application Integration,Google\n2,Pubsub,Google`. |
| Input parameter | **json:** JSON to be converted into csv. **headers:** Headers list for csv output. If no value is provided, it would use all the headers. |
| Return type | `STRING` |
| Output | Returns the csv string from json in given format. |
|---|---|

*** ** * ** ***

### `Resolve JSON Path`

| Syntax | ```html resolveJsonPath(obj, path) ``` |
| Description | Resolves a JSON path on a given JSON object by using the `JSONPath` reference. |
| Input parameter | **obj:** The input JSON object. **path:** The JSON path string. |
| Return type | `JSON` |
| Output | Returns the JSON object or value at the provided path. |
|---|---|

*** ** * ** ***

### `JSON to String`

| Syntax | ```html jsonToString(input) ``` |
| Description | Converts the specified JSON object or array into a JSON string. For example, `f.jsonToString({"name": "Jane"})` returns `"{\"name\":\"Jane\"}"`. |
| Input parameter | **input:** The input JSON object or array to convert into a string. |
| Return type | `STRING` |
| Output | Returns the string representation of the input JSON value. |
|---|---|

*** ** * ** ***

### `Parse XML JsonML`

| Syntax | ```html parseXmlJsonml(input, preserveWhitespace = false) ``` |
| Description | Parses the specified input XML string into a JSON array in [JsonML](https://en.wikipedia.org/wiki/JsonML) format. For example, `f.parseXmlJsonml("<svg><circle>FooBar</circle></svg>")` returns `["svg", ["circle", "FooBar"]]`. |
| Input parameter | **input:** The input XML string to parse. **preserveWhitespace:** A boolean value that indicates whether to preserve leading and trailing whitespace in XML character data. The default value is `false`. |
| Return type | `ARRAY` |
| Output | Returns the JsonML array representation of the input XML string. |
|---|---|

## Recommendation

- Learn how to add and configure a [Data Transformer Script task](https://docs.cloud.google.com/application-integration/docs/configure-data-transformer-script-task.md.txt)