> For the complete documentation index, see [llms.txt](https://archivedocs.stackstate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://archivedocs.stackstate.com/5.1/develop/reference/stj/using_stj.md).

# Using STJ

## Overview

StackState's graph is entirely configured using JSON. To make it easy to work with large quantities of (often repetitive) JSON, StackState comes with the StackState Template JSON format (STJ).

STJ is based on [handlebars (handlebarsjs.com)](https://handlebarsjs.com/) and comes with a number of [StackState functions](/5.1/develop/reference/stj/stj_reference.md).

## Handlebars syntax

StackState template files use handlebars. Content that is placed between double curly brackets `{{ some content }}` is included in the output. The example below shows handlebars used in a component template:

{% code lineNumbers="true" %}

```
[{
  "_type": "Component",
  "checks": [],
  "streams": [],
  "labels": [],
  "name": "{{ name }}",
  "description": "{{ description }}",
  "type" : {{ componentTypeId }},
  "layer": {{ layerId }},
  "domain": {{ domainId }},
  "environments": [{{ environmentId }}]
}]
```

{% endcode %}

### Conditionals: #if / else

Run some template code conditionally if a variable has a value.

{% tabs %}
{% tab title="Template" %}

```
{{# if description }}
"description": "{{ description }}",
{{else}}
"description": "noop",
{{/ if }}
```

{% endtab %}

{% tab title="Data" %}

```
[ description: "hello world" ]
```

{% endtab %}

{% tab title="Result" %}

```
"description": "hello world"
```

{% endtab %}
{% endtabs %}

### Looping: #each

Loop over an array or map of data.

{% tabs %}
{% tab title="Template" %}

```
[
  {{# each names }}
  "hello {{this}}",
  {{/ each }}
  "bye y'all!"
]
```

{% endtab %}

{% tab title="Data" %}

```
[ names: [ "stackstate", "handlebars" ]]
```

{% endtab %}

{% tab title="Result" %}

```
[
  "hello stackstate",
  "hello handlebars",
  "bye y'all!"
]
```

{% endtab %}
{% endtabs %}

## StackState handlebars functions

StackState adds a number of function to the handlebars syntax. You can use these to create complex JSON results.

➡️ [Learn more about the available handlebars functions](/5.1/develop/reference/stj/stj_reference.md)

## Component and relation templates

Templates are used to create topology.

➡️ [Learn more about component and relation templates](/5.1/configure/topology/sync.md#template-functions)

## See also

* [StackState Template Language Functions](/5.1/develop/reference/stj/stj_reference.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://archivedocs.stackstate.com/5.1/develop/reference/stj/using_stj.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
