# JSON to JSON Schema

Paste JSON and get a JSON Schema — types, required fields, unions, and formats (email, uri, date-time, uuid) inferred. Draft 2020-12 or Draft-07, in-browser, free.

## Run it

- **CLI:** `gizza tool json-to-json-schema '{ "name": "Ada", "email": "ada@example.com", "roles": ["admin"] }'`
- **Web:** https://gizza.ai/tools/json-to-json-schema/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/json-to-json-schema/tool.json

## Inputs

- `json` — JSON sample _(field)_
- `draft` — Schema draft _(field)_
- `additional_properties` — Allow extra properties _(field)_
- `required` — Mark seen keys required _(field)_
- `detect_formats` — Detect string formats _(field)_
- `title` — Root title (optional) _(field)_

## Output

- JSON Schema (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `json` — JSON sample
- `draft` — Schema draft
- `additional_properties` — Allow extra properties
- `required` — Mark seen keys required
- `detect_formats` — Detect string formats
- `title` — Root title (optional)

Example: `https://gizza.ai/tools/json-to-json-schema/?json=%7B%20%22name%22%3A%20%22Ada%22%2C%20%22email%22%3A%20%22ada%40example.com%22%2C%20%22roles%22%3A%20%5B%22admin%22%5D%20%7D&draft=2020-12&additional_properties=true&required=true&detect_formats=true&title=User`

---

## About this tool

**JSON to JSON Schema** infers a practical JSON Schema from one pasted JSON
example or from an array of examples. It is useful when you have sample API
responses, config objects, event payloads, or webhook fixtures and want a
starting schema without writing every property by hand.

- **Objects and arrays are inferred recursively**: nested objects become
  `properties`, arrays become `items`, and arrays with several objects merge the
  observed item shapes.
- **Required keys are data-driven**: keys present in every merged object are
  listed under `required`; keys missing in some examples become optional.
- **Mixed values become unions**: for example `[1, "two"]` produces an item type
  that accepts both `integer` and `string`.
- **String formats are detected** when enabled: email, URI, date-time, date,
  UUID (Draft 2020-12), and IPv4.
- **Strict by default**: `additionalProperties: false` is emitted unless you turn
  on “Allow extra properties”.

Everything runs locally in your browser through WebAssembly. Your sample JSON is
not uploaded.

### Worked example

Input:

```json
[{ "id": 1, "email": "ada@example.com" }, { "id": 2, "email": "grace@example.com", "admin": true }]
```

Output excerpt:

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "admin": { "type": "boolean" },
      "email": { "type": "string", "format": "email" },
      "id": { "type": "integer" }
    },
    "required": ["email", "id"],
    "additionalProperties": false
  }
}
```

### Limits & edge cases

- This is inference, not proof. A small sample may miss optional fields, allowed
  enum values, minimums, maximums, string lengths, or domain-specific rules.
- Empty arrays infer `items: {}` because there are no elements to learn from.
- Incompatible shapes (for example sometimes an object and sometimes a string)
  are intentionally widened rather than guessed narrowly.
- It does not validate future JSON against the schema; use the generated schema
  in your validator of choice.

## FAQ

<details>
<summary>Can I infer from more than one example?</summary>

Yes. Paste a JSON array of example objects. The tool merges the item schemas:
properties seen in every object stay required, while properties missing from at
least one object become optional.

</details>

<details>
<summary>Why did a field become optional?</summary>

A property is required only when it appears in every merged object at that level.
If one sample omits it, the generated schema still includes the property type but
leaves it out of the `required` array.

</details>

<details>
<summary>What does “Allow extra properties” change?</summary>

By default the schema is strict and emits `additionalProperties: false` on
objects. Turning this option on omits that keyword, allowing validators to accept
keys that were not present in the sample.

</details>

<details>
<summary>Which JSON Schema drafts are supported?</summary>

The tool emits either Draft 2020-12 (default) or Draft-07. Draft choice changes
the `$schema` URI; UUID format detection is emitted only for Draft 2020-12 because
Draft-07 did not define a `uuid` format.

</details>

<details>
<summary>Does this replace reviewing the schema manually?</summary>

No. It creates a solid starting point from observed data, but you should still
review business rules such as enumerations, numeric bounds, string lengths,
patterns, and fields that did not appear in your examples.

</details>

## Related tools

- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
- [Bencode decoder](https://gizza.ai/tools/bencode-decoder/): Decode bencode (the BitTorrent / .torrent serialization format) into readable JSON, and re-encode JSON back into canonical bencode — in your browser. Nothing is uploaded.
- [CAMT.053 Statement Parser](https://gizza.ai/tools/camt053-parse/): Parse a camt.053 (or camt.052/054) ISO 20022 bank statement XML into JSON or CSV in your browser: balances, dates, counterparties, references. No upload.
- [CSV Cell Diff](https://gizza.ai/tools/csv-cell-diff/): Compare two CSVs column-by-column and highlight every individual cell that changed, plus added and removed rows and columns.
- [Change CSV Delimiter](https://gizza.ai/tools/csv-change-delimiter/): Re-save CSV or delimited data with a different separator (comma, tab, semicolon, pipe) with correct requoting — in your browser. Free, private, no upload.
