Skip to content
OddsockLocal
Local
Source text
{
  "color": "red",
  "count": 2
}
1 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste one JSON value into Source text. An object, an array, or a single scalar all work.
  2. There are no options. The schema is inferred from that value alone.
  3. Read properties, the type of each value, and required.
  4. Copy the schema. Add formats and optional keys by hand where the sample was narrower than the contract.

What is JSON Schema from a sample?

A sample payload is the fastest way to sketch a contract, as long as you remember it only describes what that sample contains. JSON Schema from a sample walks the value and emits a draft 2020-12 schema. Objects become type object, with a properties map and a required array of every key on that object. Strings, integers, numbers, booleans, and null are typed from the value. Arrays become type array.

Read more

Two different object shapes inside one array become anyOf, not a single object with optional keys. A key that is absent from the sample is absent from the schema. count: 2 is an integer. A decimal would be a number. The page does not invent formats, enums, or minimums. It records the shape you pasted.

Use cases

  • An API author pastes a real response and uses the schema as the first draft of the contract.
  • A reviewer checks that color is a string and count is an integer before writing examples.
  • A team comparing two payloads looks at anyOf when an array mixes object shapes.
  • A documentation pass attaches the inferred schema next to the sample in a design note.
  • Someone generating types later wants the schema's required list as a checklist of keys the sample always had.

Schema for color and count

{"color":"red","count":2}

{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "color": { "type": "string" }, "count": { "type": "integer" } }, "required": ["color", "count"] }

Why use Oddsock

The inferred schema is a faithful picture of one sample, including the required list, so you can see what the example accidentally made mandatory.

Related tools

Using this tool

The sample included them. The inference has no second document to show a key that can be omitted. Remove a key from required if your API allows it to be absent.