CLI

# hotcfg schema infer

Write a JSON Schema from your existing JSON config files, as a starting point for a bin's schema.

usage

```
hotcfg schema infer <file.json>... [-o <file>]
```

Writes a [JSON Schema](https://hotcfg.run/docs/guides/schemas) that accepts every file you give it, so you don't start a bin's schema from an empty page. Give it the config you already have, from each environment if they differ:

terminal

```
$ hotcfg schema infer dev.json staging.json production.json -o schema.json
Wrote schema.json. Review and tighten it (enums, minimums, optional keys), then paste it into the bin's Schema tab, or create a bin with it: hotcfg bins create <bin_id> --schema schema.json
```

Needs CLI 0.4.0 or later. It reads local files only: no key and no network request. Without `-o`, the schema goes to standard output. `-` reads a file from standard input.

The dashboard does the same with **Generate from payloads** on a bin's **Schema** tab, from what each environment serves now, and gives the same schema for the same JSON.

## What it writes

For this file:

flags.json

```
{
  "features": { "checkout_v2": true },
  "limits": { "max_upload_mb": 25 },
  "regions": [
    { "id": "eu", "weight": 1 },
    { "id": "us", "weight": 0.5, "beta": true }
  ]
}
```

It writes:

schema.json

```
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "features": {
      "type": "object",
      "properties": { "checkout_v2": { "type": "boolean" } },
      "required": ["checkout_v2"]
    },
    "limits": {
      "type": "object",
      "properties": { "max_upload_mb": { "type": "integer" } },
      "required": ["max_upload_mb"]
    },
    "regions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "weight": { "type": "number" },
          "beta": { "type": "boolean" }
        },
        "required": ["id", "weight"]
      }
    }
  },
  "required": ["features", "limits", "regions"]
}
```

The rules:

- **Every value gets its type.** A whole number is `integer`; if any example has a fraction there, it's `number`.
- **Every key is required,** in the order the file has them. Keys that aren't listed are still allowed, so adding a key to the config later doesn't need a schema change first.
- Array elements are merged into one `items` schema. A key is required only if every element has it, like `beta` above.
- **Several files are merged the same way,** so the schema accepts each of them. A key in only some files is optional.
- **Mixed types** become a list of types (`"type": ["string", "null"]`), or `anyOf` when an object or array is among them. An empty array gets no `items`.

## Before you save it

The schema only knows what your examples show. Read it through and tighten it where you know more:

- Make keys optional that your app copes without: remove them from `required`.
- Turn strings with a few fixed values into an `enum`, such as `"theme": { "enum": ["light", "dark"] }`.
- Add the limits your app relies on: `minimum`, `maximum`, `minLength`, `pattern`.
- Forbid unknown keys where a typo should be refused: `"additionalProperties": false`.

Then create a bin with it, or paste it into an existing bin's **Schema** tab. Saving checks that every environment's current payload still passes.

## Flags

| Flag | Does |
| --- | --- |
| `-o`, `--out <file>` | Write the schema to this file instead of standard output. |

| Exit code | Meaning |
| --- | --- |
| `0` | The schema was written. |
| `1` | A file couldn't be read, or isn't valid JSON. |
| `2` | No file was given. |

Last updated 17 November 2026
