# asJsonObject() and JSON parsing in Jira Automation

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

asJsonObject(key) wraps a value in a JSON object with the key you choose. asJsonObjectArray(key) copies one property of every object in a list. jsonStringToObject() and xmlToJson() go the other way: they turn JSON or XML text into an object whose keys you read with a dot.

## Syntax

```
{{text.asJsonObject("keyName")}}
{{list.asJsonObjectArray("keyName")}}
{{jsonStringToObject(text)}}
{{xmlToJson(xmlString)}}
```

## Arguments

- `keyName` (required: yes): The name of the key in the resulting JSON object, in double quotes. asJsonObjectArray() can only copy the key of the property it reads.
- `text / xmlString` (required: yes): The JSON or XML text to parse, such as the body of a web response.

## Works on

- Fields: text values and lists for the as functions; any smart value that holds JSON or XML text for the parsers.
- Returns: a JSON object or array written as text, or a parsed object.

## Examples

```
{{issue.summary.asJsonObject("title")}}
```

Wrap the summary in an object with a key of your choice.

Result:

```
{ "title": "Hello World!" }
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.labels.first.asJsonObject("label")}}
```

The same for the first label, to send it under the key an API expects.

Result:

```
{ "label": "checkout" }
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.labels.asJsonObject("label").asJsonArray}}
```

Chain asJsonArray after asJsonObject on a list to get a proper JSON array of objects.

Result:

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

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.comments.asJsonObjectArray("body")}}
```

Extract only the body of every comment as an array of objects.

Result:

```
[{ "body": "First comment from QA" },{ "body": "Second comment: fixed in build 42" }]
```

Run on Jira Cloud on 29 Nov 2026.

```
{{jsonStringToObject("{\"value\": \"Hi\"}").value}}
```

Parse a JSON text and read one key with a dot.

Result:

```
Hi
```

Run on Jira Cloud on 29 Nov 2026.

```
{{jsonStringToObject("{\"value\": \"Hi\"}")}}
```

Without a key the parsed object prints as key=value.

Result:

```
{value=Hi}
```

Run on Jira Cloud on 29 Nov 2026.

## Pitfalls

- asJsonObject on a list prints the objects separated by a comma, without brackets: `{ "label": "checkout" }, { "label": "demo" }`. Add `.asJsonArray` to get a valid array (checked on Jira Cloud, November 2026).
- asJsonArray on a single object, such as `issue.summary.asJsonObject("title")`, renders an empty string. It expects a list.
- jsonStringToObject() fails on text that is not JSON. A description such as Checkout page redesign gives `Failed to convert string to JSON. Error: Unrecognized token 'Checkout'` and the rule logs an error.
- `webResponse.body` exists only after a Send web request action. Without one, both parsers fail, as the two examples taken from the Atlassian page show.

## Related

- [asJsonString, asJsonStringArray, asJsonArray](https://goingstellar.ro/reference/smart-values/asjsonstring/)
- [htmlEncode, xmlEncode, jsonEncode and quote()](https://goingstellar.ro/reference/smart-values/htmlencode-xmlencode-jsonencode/)
- [join()](https://goingstellar.ro/reference/smart-values/list-join/)
- [Default values {{value|default}}](https://goingstellar.ro/reference/smart-values/default-values/)
- [{{issue.comments}}](https://goingstellar.ro/reference/smart-values/issue-comments/)

## Sources

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

