# asJsonString and JSON arrays in Jira Automation: examples

URL: https://goingstellar.ro/reference/smart-values/asjsonstring/

These functions turn field values into JSON literals, so you can build the body of a web request without breaking it on quotes or line breaks. asJsonString wraps one text value in quotes and escapes it. asJsonStringArray and asJsonArray write a list as a JSON array.

## Syntax

```
{{text.asJsonString}}
{{list.asJsonStringArray}}
{{list.asJsonArray}}
```

## Works on

- Fields: text values for asJsonString, lists of text or numbers for asJsonStringArray, lists of numbers for asJsonArray.
- Returns: a JSON string or a JSON array, written as text.

## Examples

```
{"text": {{issue.description.asJsonString}}}
```

Put the description in a JSON body. The quotes come from the function, so none are typed around it.

Result:

```
{"text": "Checkout page redesign. Customer reported the total is wrong."}
```

Run on Jira Cloud on 29 Nov 2026.

```
{"summary": {{issue.summary.concat(" says \"hi\"").asJsonString}}}
```

Quotes inside the text are escaped, so the body stays valid JSON.

Result:

```
{"summary": "Hello World! says \"hi\""}
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.labels.asJsonStringArray}}
```

Write the labels as a JSON array of strings.

Result:

```
["checkout","demo"]
```

Run on Jira Cloud on 29 Nov 2026.

```
{"labels": {{issue.labels.asJsonStringArray}}}
```

Place the array as a field of a request body.

Result:

```
{"labels": ["checkout","demo"]}
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.comments.id.asJsonArray}}
```

Write numeric ids as a JSON array of numbers, without quotes.

Result:

```
[10411,10412]
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.comments.id.asJsonStringArray}}
```

The same ids as an array of strings, for an API that expects ids in quotes.

Result:

```
["10411","10412"]
```

Run on Jira Cloud on 29 Nov 2026.

## Pitfalls

- asJsonArray is for numbers. On text it leaves the quotes out: `{{issue.labels.asJsonArray}}` gives `[checkout,demo]`, which is not valid JSON (checked on Jira Cloud, November 2026). Chain `asJsonString.asJsonArray` or use asJsonStringArray.
- asJsonString on an empty value gives an empty string, not `""`. A body such as `{"version": {{issue.fixVersions.first.name.asJsonString}}}` becomes invalid JSON on a work item without versions, while asJsonStringArray gives `[]` on an empty list.
- Do not type quotes around asJsonString: the function adds them, as the first example shows.

## Related

- [asJsonObject(), xmlToJson(), jsonStringToObject()](https://goingstellar.ro/reference/smart-values/asjsonobject/)
- [htmlEncode, xmlEncode, jsonEncode and quote()](https://goingstellar.ro/reference/smart-values/htmlencode-xmlencode-jsonencode/)
- [join()](https://goingstellar.ro/reference/smart-values/list-join/)
- [split()](https://goingstellar.ro/reference/smart-values/split/)
- [{{issue.key}}, {{issue.summary}} and other issue fields](https://goingstellar.ro/reference/smart-values/issue-fields/)

## Sources

- [Jira smart values: JSON functions (Atlassian Support)](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/)

