> For the complete documentation index, see [llms.txt](https://sevenval.gitbook.io/flat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sevenval.gitbook.io/flat/develop/reference/templating/comma.md).

# {{,}}

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 `{{: …}}`](/flat/develop/reference/templating/pair-producer.md) 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](/flat/develop/reference/templating/loop.md) produces commas between its productions, too. In loop bodies comma commands are allowed but usually not necessary.
