自動化スマート値 - 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.
Jira Automation テンプレート ライブラリでスマート バリューを使用する方法をご確認ください。
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
JSON 形式でテキスト プロパティを文字列としてレンダリングします。これにより、文字列内のすべての特殊文字がエスケープされます。
{{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
値のリストを JSON でエンコードされた値のリストに変換するか、数字のリストを JSON でエンコードされた文字列のリストに変換します。
{{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
数値のリストを JSON でエンコードされたリストに変換します。
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
.
正しくレンダリングされないため、テキスト値のリストにこの関数を使わないでください。
{{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
テキスト値を JSON キーと値のペア オブジェクトに変換します。keyName プロパティは、以下のとおり、フィールド名として使用されます。
{{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)
オブジェクトの 1 つの属性を JSON キーと値のペア オブジェクトに抽出できます。
この関数では、キーの名前を変更できません。変更するには、この関数を他の関数とチェーンする必要があります。
以下の例では、2 つの値 ("Bob" と "Jill") が選択されている複数選択のカスタム フィールドを使用して、別のフィールドでどのように機能するかが示されています。複数選択のカスタム フィールドは、ID と値のプロパティを持つオブジェクト リストです。
{{issue.fixVersions.asJsonObjectArray("name")}}
// Produces
[{ "name": "Version 2.0" },{ "name": "Version 3.0" }]
{{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.
XML データの文字列表現を受け取り、JSON オブジェクトに変換します。これにより、ドット表記を使用して XML データのプロパティにアクセスできます。
例
Let’s say your rule uses the Send web request action. To access this data as a JSON, you’d use {{xmlToJson(webResponse.body)}}
.
XML にブロック <item>Hello World</item>
が含まれている場合、スマート値 {{xmlTojson(webResponse.body).item}}
は「Hello World」という文字列を返します。
関数をチェーンする
上の 2 つの関数を連結して、オブジェクトからプロパティを取得し、JSON のキー値ペアに変換ます。このとき、キーの名前も変更します。
次の例では、fixVersions というネームプロパティを選択しています。
{{issue.fixVersions.name.asJsonObject("title").asJsonArray}}
// Produces
[{ "title": "Version 2.0" },{ "title": "Version 3.0" }]
以下の例では、直接 asJsonStringArray を使って同じ結果を得ていますが、関数をつなげて目当ての値を返す方法を示しています。
{{issue.fixVersions.name.asJsonString.asJsonArray}}
// Produces
["Version 2.0","Version 3.0"]
この内容はお役に立ちましたか?