# 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](https://docs.devhub.com/data-sources/external-contexts) 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"},...];
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devhub.com/themes-and-custom-templates/advanced-examples/serializing-data-to-json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
