Jira smart values - JSON functions

The following smart values are available to convert issue fields into JSON format, when setting up a rule. This is usually used in advanced field editing and on the Send outgoing web request action.

Check out how we use smart values in our Jira automation template library.

The examples below assume an issue with two versions (Version 2.0 and Version 3.0), a custom single select called Decision with a selected value of Yes, and a summary titled Hello World.

asJsonString

  • Applies to: text type fields and values

Render a text property as a string in JSON format. This will escape any special characters contained in the string.

1 2 3 {{issue.fixVersions.first.name.asJsonString}} // Produces "Version 2.0"
1 2 3 {{issue.summary.asJsonString}} // Produces "Hello World"
1 2 3 {{issue.Decision.value.asJsonString}} // Produces "Yes"

asJsonStringArray

  • Applies to: lists of text/number type values

Transforms a list of values into a JSON encoded list of values, or converts a list of numbers into a list of JSON encoded strings.

1 2 3 {{issue.fixVersions.name.asJsonStringArray}} // Produces ["Version 2.0","Version 3.0"]
1 2 3 {{issue.fixVersions.id.asJsonStringArray}} // Produces ["10046","10047"]

asJsonArray

  • Applies to: lists of number type values

Transforms a list of number values into a JSON encoded list.

The second example below uses a text function to remove the word version from each fix version. The returned list (“2.0” and “3.0”) can then be converted to a list of numbers using asJsonArray.

Do not use this function with lists of text values, as they will not render correctly.

1 2 3 {{issue.fixVersions.id.asJsonArray}} // Produces [10046,10047]
1 2 3 {{issue.fixVersions.name.right(3).asJsonArray}} // Produces [2.0,3.0]

asJsonObject(keyName)

  • Applies to: text type fields and values

Transforms a text value into a JSON key/value pair object. The keyName property is used as the name of the field, as shown below.

1 2 3 {{issue.summary.asJsonObject("title")}} // Produces { "title": "Hello World" }
1 2 3 {{issue.Decision.value.asJsonObject("implementing")}} // Produces { "implementing": "Yes" }
1 2 3 {{issue.fixVersions.first.name.asJsonObject("title")}} // Produces { "title": "Version 2.0" }

asJsonObjectArray(keyName)

  • Applies to: lists of objects (such as fixVersions or a custom multi select)

Allows you to extract one attribute of an object into a JSON key/value pair object.

This function does not allow you to change the name of the key. To do this, you’ll need to chain this function with another.

The example below uses a custom multi select field with two values selected ("Bob" and "Jill") to show how this would work on another field. A custom multi select field is a list of objects that have id and value properties.

1 2 3 {{issue.fixVersions.asJsonObjectArray("name")}} // Produces [{ "name": "Version 2.0" },{ "name": "Version 3.0" }]
1 2 3 {{issue.customfield_10099.asJsonObjectArray("value")}} // Produces [{ "value": "Bob" },{ "value": "Jill" }]

xmlToJson(xmlString)

  • Applies to: any smart value that returns XML data, such as {{webResponse}} from the Send web request action or {{webhookData}} from the Incoming webhook trigger.

Takes a string representation of XML data and converts it to a JSON object. This allows you to access properties of your XML data using dot notation.

Example

Let’s say your rule uses the Send web request action. To access this data as a JSON, you’d use {{xmlToJson(webResponse.body)}}.

If the XML contains a block <item>Hello World</item>, then the smart value {{xmlTojson(webResponse.body).item}} would return the string “Hello World”.

Chaining functions

You can chain two of the above functions to extract a property from an object into a JSON key/value pair, while also changing the name of the key.

In the following example, we're selecting the name property of the fixVersions:

1 2 3 {{issue.fixVersions.name.asJsonObject("title").asJsonArray}} // Produces [{ "title": "Version 2.0" },{ "title": "Version 3.0" }]

The example below achieves the same outcome as using asJsonStringArray directly, but shows how functions can be chained to return the desired value.

1 2 3 {{issue.fixVersions.name.asJsonString.asJsonArray}} // Produces ["Version 2.0","Version 3.0"]

Additional Help