JSON to io-ts Codec Converter
Paste a JSON sample to instantly generate a matching io-ts codec, using t.intersection for objects with optional properties. Free online developer tool.
Paste JSON
io-ts Codec
io-ts codec definitions will appear here...
Free JSON to io-ts Codec Converter
Paste a JSON sample to instantly generate a matching io-ts codec, following its convention of declaring required and optional properties separately.
How to Use It
Paste any JSON object or array, or click "Load Example." The tool infers a type shape and emits a t.type({...}) codec for every object whose properties are all required. If an object has a mix of required and optional properties, it emitst.intersection([t.type({...}), t.partial({...})]) instead — the standard io-ts pattern, since t.type alone can't express optional keys. Arrays becomet.array(...), and nullable fields are wrapped in t.union([T, t.null]).
Example
Given {"name": "Ann", "age": 30, "tags": ["a","b"], "address": {"city": "NYC", "zip": null}}, the tool emits const RootAddress = t.type({ city: t.string, zip: t.null }); and aRoot codec referencing it, with tags: t.array(t.string).
Common Use Cases
- Validating API boundary data at runtime in an fp-ts / io-ts codebase.
- Getting the required/optional split right without hand-writing t.intersection boilerplate.
- Deriving a static TypeScript type from the codec with io-ts's
t.TypeOf<typeof Codec>.
FAQs
Why does io-ts need t.intersection for optional fields?
Unlike Zod's per-field .optional(), io-ts models optionality at the object level:t.type declares required properties and t.partial declares optional ones. To combine both in a single object, io-ts's documented pattern is to intersect the two codecs.
Does the generated code include an io-ts import?
No — only the codec declarations are generated. Addimport * as t from "io-ts"; at the top of the file where you paste the output.
Is my JSON uploaded anywhere?
No — parsing and codec generation happen entirely client-side in your browser. Nothing you paste is sent to a server.
