スマート バリュー - JSON 関数
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.
{{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
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.
{{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
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.
{{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
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.
{{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)
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.
{{issue.fixVersions.asJsonObjectArray("name")}}
// Produces
[{ "name": "Version 2.0" },{ "name": "Version 3.0" }]
{{issue.customfield_10099.asJsonObjectArray("value")}}
// Produces
[{ "value": "Bob" },{ "value": "Jill" }]
関数をチェーンする
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:
{{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.
{{issue.fixVersions.name.asJsonString.asJsonArray}}
// Produces
["Version 2.0","Version 3.0"]