# {{,}}

Produces a literal comma (`,`) exactly if it is required for valid JSON.

## Usage

If conditional expressions follow each other, it can be hard to say whether a comma is needed or not to obtain valid JSON:

```markup
<template>
{
  {{if maybe }}   "foo": "bar" {{end}} {{// place a comma here? }}
  {{if perhaps }} "bar": "baz" {{end}} {{// or here? }}
  {{: may-be-empty }}
}
</template>
```

If the first condition is `true`, a name/value pair will be produced. If and only if the second condition is `true` as well, a comma will be needed to separate both pairs. The same applies to the following [pair producer `{{: …}}`](https://sevenval.gitbook.io/flat/develop/reference/templating/pair-producer) which may yield nothing.

To avoid having to repeat various combinations of the conditions to decide whether or not to emit a comma, use the comma command `{{,}}` to automatically produce all required commas:

```markup
<template>
{
  {{if maybe }}   "foo": "bar" {{end}} {{,}}
  {{if perhaps }} "bar": "baz" {{end}} {{,}}
  {{: may-be-empty }}
}
</template>
```

The `{{,}}` could be placed in the body of `{{if}}` as well:

```javascript
  {{if maybe }}   "foo": "bar" {{,}} {{end}}
  {{if perhaps }} "bar": "baz" {{,}} {{end}}
```

> 📎 Note that the comma may appear after some whitespace in the output string.

The use of the `{{,}}` should be seen as a last resort, because it impairs the template's readability. In many cases, the decision whether to place a comma or not can be made a priori by reordering the name/value pairs, producing *leading* commas in conditionals or having a fixed `{{else}}` block.

The [`{{loop}}` command](https://sevenval.gitbook.io/flat/develop/reference/templating/loop) produces commas between its productions, too. In loop bodies comma commands are allowed but usually not necessary.


---

# 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://sevenval.gitbook.io/flat/develop/reference/templating/comma.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.
