> For the complete documentation index, see [llms.txt](https://developer.frontitude.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.frontitude.com/developer-cli/file-formats/web--json.md).

# Web (.json)

Frontitude supports multiple JSON formats.

{% hint style="info" %}
Format is automatically detected based on the file extension, so there’s no need to specify the format type when using it. ✨
{% endhint %}

{% hint style="info" %}
`frontitude push` supports the **flat** format only. Nested, Metadata, and multi-locale Translations formats are pull-only.
{% endhint %}

## Flat

**Example**

{% code fullWidth="false" %}

```json
{
  "info_tooltip.title": "No worries, you won’t be charged",
  "info_tooltip.paragraph": "You can review this order before it's final"
}
```

{% endcode %}

## Nested

**Example**

```json
{
  "info_tooltip": {
    "title": "No worries, you won’t be charged",
    "paragraph": "You can review this order before it's final"
  }
}
```

## Metadata

Frontitude supports an extended JSON format, called ***Metadata***, which basically includes all metadata stored in Frontitude for each copy item.

**Example**

```json
{
  "info_tooltip.title": {
    "value": "No worries, you won’t be charged",
    "status": "Final",
    "tags": ["Title", "Info tooltip", "Payment flow"],
    "isMixedStyle": false,
    "note": "A tooltip title, should grab attention and give users more information about next step",
    "createdAt": "2021-11-24T11:37:44.896Z",
    "updatedAt": "2021-11-25T10:12:34.131Z",
    "lastEditedBy": "Owen Fogel",
    "frontitudeLink": "https://app.frontitude.com/project/becaf236-53e7-473a-be41-3d6f7fc66168?edit=10278ce3-e802-4750-9b33-ef31f70e7bd0"
  },
  "info_tooltip.paragraph": {
    "value": "No worries, you won’t be charged",
    "status": "Final",
    "tags": ["Title", "Info tooltip", "Payment flow"],
    "isMixedStyle": false,
    "note": "A tooltip title, should grab attention and give users more information about next step",
    "createdAt": "2021-11-24T11:37:44.896Z",
    "updatedAt": "2021-11-25T10:12:34.131Z",
    "lastEditedBy": "Owen Fogel",
    "frontitudeLink": "https://app.frontitude.com/project/becaf236-53e7-473a-be41-3d6f7fc66168?edit=10278ce3-e802-4750-9b33-ef31f70e7bd0"
  }
}
```

## Translations (Single file)

This format assumes that translations in all languages are defined in a single file. This is usually the case in small/medium applications.

**Example**

{% code title="strings.json" %}

```json
{
  "en": {
    "info_tooltip.title": "No worries, you won’t be charged",
    "info_tooltip.paragraph": "You can review this order before it's final"
  },
  "es": {
    "info_tooltip.title": "No te preocupes, no se te cobrará",
    "info_tooltip.paragraph": "Puedes revisar este pedido antes de que sea definitivo"
  },
  "de": {
    "info_tooltip.title": "Keine Sorge, es entstehen Ihnen keine Kosten",
    "info_tooltip.paragraph": "Sie können diese Bestellung überprüfen, bevor sie endgültig ist"
  },
  "ja": {
    "info_tooltip.title": "請求されませんのでご安心ください",
    "info_tooltip.paragraph": "この注文を確定する前に確認できます"
  }
}
```

{% endcode %}

## Translations (Separate files)

This format assumes that translations are stored in separated files, each dedicated for a specific language. This is usually the case in large applications.

**Example**

{% code title="strings.json" %}

```json
{
  "info_tooltip.title": "No worries, you won’t be charged",
  "info_tooltip.paragraph": "You can review this order before it's final"
}
```

{% endcode %}

{% code title="strings-es.json" %}

```json
{
  "info_tooltip.title": "No te preocupes, no se te cobrará",
  "info_tooltip.paragraph": "Puedes revisar este pedido antes de que sea definitivo"
}
```

{% endcode %}

{% code title="strings-fr\_CA.json" %}

```json
{
  "info_tooltip.title": "Ne t'inquiète pas, tu ne seras pas facturé",
  "info_tooltip.paragraph": "Tu peux revoir cette commande avant qu'elle soit définitive"
}‍
```

{% endcode %}

## Variable and plural formats

{% hint style="info" %}
Available from CLI version 2.0.0 and above.
{% endhint %}

By default, `pull` writes variables as `{{name}}` and plurals as one key per form, such as `items_one` and `items_other`. If your file uses another syntax, set `variableFormat` and `pluralFormat` in `frontituderc.json`, as in [this example](https://developer.frontitude.com/developer-cli/configuration-file.md#custom-variable-and-plural-formats). `pull` writes that syntax, and `push` reads it back. Without these settings, nothing changes.

The settings apply to `.json` files only. Other file types ignore them, with a [warning](https://developer.frontitude.com/developer-cli/errors.md#warnings). The `--variable-format` and `--plural-format <suffix|joined>` flags override the config file. See [Configuration file](https://developer.frontitude.com/developer-cli/configuration-file.md#variableformat) for every option.

### Variables

The Frontitude text `Hello {{first_name}}, you have {{count}} new messages` is pulled like this with `"variableFormat": "{name}"`:

```json
{
  "inbox.summary": "Hello {first_name}, you have {count} new messages"
}
```

And like this with `"variableFormat": "%{name}"`:

```json
{
  "inbox.summary": "Hello %{first_name}, you have %{count} new messages"
}
```

`push` does the reverse: with `%{name}`, `"welcome.title": "Hello %{first_name}"` becomes `Hello {{first_name}}` in Frontitude.

* Variable names use letters, digits, and underscores. Other tokens, such as `{{first name}}`, stay as they are, with a warning.
* The template is matched literally, spaces included.
* A template with text only before `name`, such as `:name`, never starts inside a word, so `10:30` stays text. But `push` reads `Starts at :30` as a variable named `30`, so check the preview. Letters, digits, and underscores after the variable are part of its name: `:counts` is the variable `counts`.

### Plurals

**Suffix** writes one key per form, with an optional `separator`. The default, `{ "style": "suffix" }`, gives:

```json
{
  "cart.items_one": "{{count}} item",
  "cart.items_other": "{{count}} items"
}
```

With `{ "style": "suffix", "separator": "." }` and `"variableFormat": "${name}"`:

```json
{
  "cart.items.one": "${count} item",
  "cart.items.other": "${count} items"
}
```

On `push`, both keys become the forms `one` and `other` of the component `cart.items`.

**Joined** writes all forms in one value, split by the `delimiter`. With `{ "style": "joined", "delimiter": " |||| " }` and `"variableFormat": "%{name}"`:

```json
{
  "cart.items": "%{count} item |||| %{count} items"
}
```

On `push`, the CLI splits the value back into the forms `one` and `other`.

The forms follow the plural forms of the file's locale, in the order `zero`, `one`, `two`, `few`, `many`, `other`. English has `one` and `other`. Russian has four forms:

```json
{
  "cart.items": "%{count} товар |||| %{count} товара |||| %{count} товаров |||| %{count} товара"
}
```

* The file's locale is the source language of your workspace, or the locale of the translation file with `--include-translations`. `push` uses the source language.
* If a plural has no text for a form, the `other` text fills that slot, without a warning. For example, French, Spanish, Portuguese, and Italian have `one`, `many`, and `other`, so the middle slot repeats the `other` text.
* A locale with one form, such as Japanese, has nothing to join. On `push`, its values are plain text.

To choose the forms yourself, set `forms`. `{ "style": "joined", "delimiter": " | ", "forms": ["zero", "one", "other"] }` with `"variableFormat": "{name}"` gives:

```json
{
  "cart.items": "No items | {count} item | {count} items"
}
```

`forms` applies to every locale file of the config, so set it only when all your locales share that layout. The plural forms of a locale come from the Node.js version that runs the CLI, and can change between Node.js releases. If your team or CI runs different Node.js versions, set `forms` to keep the number of forms stable.

On `push`, each joined value must have as many forms as the locale, or as `forms`. Otherwise the push fails and sends nothing. See [Variable and plural format errors](https://developer.frontitude.com/developer-cli/errors.md#variable-and-plural-format-errors).

### Nested and metadata output

With `--nested` and `--include-metadata`, `pull` converts only variables. Plurals stay as Frontitude stores them, and a non-default `pluralFormat` adds a warning. You can't push nested or metadata files: `push` needs flat string values.

### Limitations

* After you change a format, the next `pull` rewrites the affected keys. A non-default `pluralFormat` also removes the old `_one` and `_other` keys of the plurals it pulls.
* When you switch back to the default, or between two non-default formats, keys in the old format stay in the file. Delete them by hand. Old keys such as `items.one` are a risk after a switch to joined: a joined `push` would create components with those names.
* With a custom `separator`, `push` reads a key that ends in the separator plus a form name (`zero`, `one`, `two`, `few`, `many`, `other`) as a plural form when the lock file or the last pull knows it as one. A key that they know as a plain key stays plain. For other keys, the keys of one stem are plural forms only when there are two or more and one ends in `other`. So `items.one` + `items.other` is a plural, but a lone `menu.other`, or `step.one` + `step.two`, stay plain keys. A suffix key whose stem is also its own key is a collision error. The same applies to `_` in the default format.
* With joined, `push` reads any value that contains the `delimiter` as a plural.

## One file per key prefix

{% hint style="info" %}
Available from CLI version 2.0.0 and above.
{% endhint %}

Put `{prefix}` in `filePath` to keep one flat `.json` file for each key prefix, for example the key `Checkout.heading` in `Checkout.json`. One `frontituderc.json` manages all the files: `pull` sends each key to the file of its prefix, and `push` reads all the files back. See [Configuration file](https://developer.frontitude.com/developer-cli/configuration-file.md#one-file-per-key-prefix) for `filePath`, `newFilePath` and `fallbackFilePath`, with examples.

### The prefix of a key

The prefix is the text before the first key delimiter. With key enforcement on, the delimiter comes from the unique key setting of your workspace: `.`, `/`, `:`, `-` or `>`. With key enforcement off, it is `.`. The file keeps the full key: `Checkout.json` holds `"Checkout.heading"`, not `"heading"`.

A key has no prefix when it has no delimiter, or starts with it. A prefix is also not usable when it cannot be a file name, because it:

* contains a character such as `/`, `\`, `:`, `?` or `*`
* is `.` or `..`, or ends with a dot or a space
* is a reserved Windows name, such as `CON` or `NUL`
* makes a file name longer than 255 bytes

### Pull

`pull` sends each key to one file:

1. The existing file of its prefix, in any folder that `filePath` matches.
2. If there is none and `newFilePath` is set, a new file there.
3. Otherwise `fallbackFilePath`, with a warning. Keys without a usable prefix, and the other cases in [`fallbackFilePath`](https://developer.frontitude.com/developer-cli/configuration-file.md#fallbackfilepath), also go there.

* `pull` asks only for texts that have a key, as if `--has-key` were set.
* A key in the wrong file, also in the fallback file, moves to the file of its prefix. Keys that Frontitude does not return, such as keys you added locally, stay where they are.
* A file that loses all its keys stays as `{}`. `pull` never deletes files. An empty file counts as `{}`.
* A key that has no text in Frontitude is not written, with a warning. A text that your file already has for that key stays.
* `pull` writes only the files whose keys or values change. It writes them with 2 spaces of indentation, LF line endings, and sorted keys. A byte order mark, CRLF line endings and tabs are not kept. The file keeps its final newline if it had one, and a new file gets one.
* `variableFormat` and `pluralFormat` apply to each file. All plural forms of one key go to the same file.
* If two files have the same prefix, `pull` stops before it asks Frontitude for texts, and writes nothing. See [`DUPLICATE_PREFIX_FILE`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors).

### Push

`push` reads every file that `filePath` matches, and `fallbackFilePath` if it exists, and sends their keys together. It never creates or moves strings files, but it writes lock files next to them. See [Lock files](https://developer.frontitude.com/developer-cli/commands.md#lock-files).

* If one key is in two files, `push` stops and sends nothing. Plural forms of one key in one file are not duplicates. See [`DUPLICATE_KEY_ACROSS_FILES`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors).
* A key in a file that its prefix does not name is still sent, with a warning. The next `pull` moves it.
* If no file matches and the fallback file does not exist, `push` stops with an error.
* A file whose name cannot be a key prefix is skipped with a warning. For example, with the delimiter `.`, `common.v2.json` is skipped, because the prefix `common.v2` contains the delimiter.

### Translation files

Put `{locale}` in every pattern, in `fallbackFilePath`, and in `newFilePath` if you set it. Then pull with `--include-translations`. Without `{locale}`, this flag is an error ([`LOCALE_TOKEN_REQUIRED`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors)).

```json
{
  "filePath": "./src/**/strings/{locale}/{prefix}.json",
  "newFilePath": "./src/pages/strings/{locale}/{prefix}.json",
  "fallbackFilePath": "./src/strings-fallback.{locale}.json"
}
```

* `{locale}` is the Frontitude locale id as it is, for example `en`, `fr_FR` or `zh_Hant_TW`. It matches only the locale ids of your workspace, so a folder such as `strings/legacy/` is not read as a locale.
* For the source language, `{locale}` is the source language of your workspace. If the workspace has none, the command stops with [`SOURCE_LANGUAGE_NOT_SET`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors).
* `{prefix}` and `{locale}` can be in one file name, as in `./src/**/strings/{prefix}.{locale}.json`.
* When a prefix has a source-language file, `pull` creates a missing translation file next to it, with the locale part replaced, even without `newFilePath`. Otherwise it uses `newFilePath` or the fallback file of that locale.
* Without `--include-translations`, `pull` writes the source-language files only. `push` reads the source-language files only, unless you use `push --update --include-translations`. See [Translations on push](https://developer.frontitude.com/developer-cli/commands.md#translations-on-push).
* When `filePath` has no `{locale}`, a file such as `Checkout-fr_FR.json` is skipped with a warning if `fr_FR` is a locale of your workspace.

### What the output looks like

The pull summary lists each changed file, then the totals:

```
Successfully pulled the latest content

    src/pages/strings/Checkout.json: 1 changed, 1 moved out
    src/pages/strings/Profile.json: 2 moved in
    src/pages/strings/Settings.json: 1 moved out

    3 files changed, 1 key added or changed, 2 moved
```

A new file shows `created`. With no file changes, the summary is `No file changes.` With no keys, it is `No keys were pulled, so no files were written.`

`--dry-run` writes nothing and lists the keys of each file: `+` added, `~` changed, `→` moves in, `←` moves out.

```
Dry run: 3 files would change. No files were written.

src/pages/strings/Checkout.json
  ~ Checkout.heading
  ← Profile.title moved out to src/pages/strings/Profile.json
src/pages/strings/Profile.json
  → Profile.header moved in from src/pages/strings/Settings.json
  → Profile.title moved in from src/pages/strings/Checkout.json
src/pages/strings/Settings.json
  ← Profile.header moved out to src/pages/strings/Profile.json
```

A new file is marked `(new)`, and the first line counts it, for example `Dry run: 2 files would change, 1 would be created. No files were written.` Files without changes are not listed.

For the warnings, see [Warnings](https://developer.frontitude.com/developer-cli/errors.md#warnings).

### Limits of multi-file output

* `--nested` and `--include-metadata` are not supported ([`MULTI_FILE_UNSUPPORTED_OPTION`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors)).
* Every strings file must hold one JSON object with text values only. A file with an object, a list, a number, `true`, `false` or `null` as a value stops `pull` and `push` before any change. See [`INVALID_STRINGS_FILE`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors).
* Don't set `pluralFormat.separator` to the key delimiter, for example `.` for both. A key can then end up in two files, and `push` stops with [`DUPLICATE_KEY_ACROSS_FILES`](https://developer.frontitude.com/developer-cli/errors.md#multi-file-output-errors). Use another separator.
