JSON functions
These smart value functions are for converting issue fields into the JSON format, usually used in advanced field editing and send web request.
The following documentation examples are assuming 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
Used to take a text property and render it as a string in JSON format. This will escape any special characters contained in the string.
{{issue.fixVersions.first.name.asJsonString}}
// Produces
"Version 2.0"
{{issue.summary.asJsonString}}
// Produces
"Hello World"
{{issue.Decision.value.asJsonString}}
// Produces
"Yes"
asJsonStringArray
- Applies to: lists of text/number type values
Used to transform a list of values into a JSON encoded list of values. It can also be used to convert a list of numbers into a list of JSON encoded strings as shown in the second example below.
{{issue.fixVersions.name.asJsonStringArray}}
// Produces
["Version 2.0","Version 3.0"]
{{issue.fixVersions.id.asJsonStringArray}}
// Produces
["10046","10047"]
asJsonArray
- Applies to: lists of number type values
Used to transform a list of number values into a JSON encoded list. The second example below shows the power of this function. We're using a text function to remove the word "version" from each fix version (so we get a list of "2.0 and "3.0") which we can then use asJsonArray to turn it into a list of numbers.
Numbers only
Make sure that you do not use this function with lists of text values as you can apply it to them but it will not render them correctly.
{{issue.fixVersions.id.asJsonArray}}
// Produces
[10046,10047]
{{issue.fixVersions.name.right(3).asJsonArray}}
// Produces
[2.0,3.0]
asJsonObject(keyName)
- Applies to: text type fields and values
Used to transform a text value into a JSON key/value pair object. The keyName property is used as the name of the field, as you can see in the examples below.
{{issue.summary.asJsonObject("title")}}
// Produces
{ "title": "Hello World" }
{{issue.Decision.value.asJsonObject("implementing")}}
// Produces
{ "implementing": "Yes" }
{{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)
This is an older function that doesn't have the flexibility of the others. It allows you to extract one attribute of an object into a JSON key/value pair object but you cannot change the name of the key.
In the example below we've got 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.
The next section shows how you can extract a property as key/value pair object while also changing the key name.
{{issue.fixVersions.asJsonObjectArray("name")}}
// Produces
[{ "name": "Version 2.0" },{ "name": "Version 3.0" }]
{{issue.customfield_10099.asJsonObjectArray("value")}}
// Produces
[{ "value": "Bob" },{ "value": "Jill" }]
Chaining functions
This example shows how 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 this case we're selecting the name property of the fixVersions.
{{issue.fixVersions.name.asJsonObject("title").asJsonArray}}
// Produces
[{ "title": "Version 2.0" },{ "title": "Version 3.0" }]
The example below is achieving the same thing as using asJsonStringArray directly but it serves to show how you could join the methods together if you wanted to.
{{issue.fixVersions.name.asJsonString.asJsonArray}}
// Produces
["Version 2.0","Version 3.0"]