> For the complete documentation index, see [llms.txt](https://docs.devhub.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devhub.com/themes-and-custom-templates/advanced-examples/serializing-data-to-json.md).

# Serializing data to JSON

Example of outputting a variable that contains a list of items.

Example list `["First Item", "Second Item"]`

```javascript
{% set myitems = ["First Item", "Second Item"] %}

var someVariable = {{ myitems|tojson|safe }};
```

Would output:

```javascript
var someVariable = ["First Item", "Second Item"];
```

## From External Context

If you are using an [External Context](/data-sources/external-contexts.md) in your template, you can serialize any filtered output to JSON.

```javascript
{% set results = external_context_name.filter({"city": "Seattle"}) %}

var someItems = {{ results|tojson|safe }};
```

Would output:

```javascript
var someItems = [{"name" "Item 1", "city": "Seattle"},...];
```
