FormatterHQ

JSON to Flow Types

Generate Flow type aliases from JSON, with optional properties, arrays and nested object types, plus an optional runtime-checked converter.

Input JSON
Output JAVASCRIPT
Ready.

How to use the JSON to Flow

  1. Paste your JSON sample (an object, or an array of objects) into the Input editor, or use Sample, Upload file or Load URL, or press Sample to try one.
  2. Set the Top-level class name, for example Task; it is converted to PascalCase. Nested types are named after their property keys.
  3. Tick Types only (no helpers) for type aliases only, or leave it off to include a Convert module that validates JSON at runtime.
  4. Press Generate (it also re-runs automatically as you edit), then use Copy or Download.

JSON to Flow type definitions

Flow, the static type checker from Meta, needs type annotations for the data your code handles. This JSON to Flow generator writes exported type aliases from a sample, starting with the // @flow pragma so Flow checks the file. Nested objects become their own types, arrays become typed arrays, and keys missing from some objects become optional properties.

Example

{ "id": 42, "title": "Write docs", "done": false,
  "owner": { "name": "Ada", "email": null },
  "subtasks": [ { "title": "Outline", "estimate": 2 }, { "title": "Draft" } ] }
// @flow

export type Task = {
    id:       number;
    title:    string;
    done:     boolean;
    owner:    Owner;
    subtasks: Subtask[];
};

export type Owner = {
    name:  string;
    email: null;
};

export type Subtask = {
    title:     string;
    estimate?: number;
};

The runtime converter

Flow types are erased when the code runs, so they cannot stop malformed data coming from an API. With Types only off, the output adds a Convert module with functions such as Convert.toTask(json) and Convert.taskToJson(value). They parse the JSON string and verify the structure against the types, throwing an error on a mismatch. The module uses CommonJS (module.exports), so require it with const Convert = require("./task").

How types are inferred

Numbers become number, booleans boolean, ISO date strings Date, and arrays T[] or Array<A | B> when elements differ, for example Array<number | string>. A key missing from some objects in the sample becomes optional (estimate?: number), and a property that is always null is typed null. Paste several records rather than one to get accurate optional properties, and give the top-level type a meaningful name in the options so nested types read well.

Refining the types

  • Exact objects: Flow object types are exact by default in recent versions; if your project uses an older configuration, write {| ... |} to forbid extra properties.
  • Read-only data: prefix properties with + (+title: string) or wrap types in $ReadOnly<...> to prevent mutation.
  • Nullable values: email: null only reflects the sample; change it to ?string (a maybe type) if the field can hold text.
  • Dates are typed as Date when the converter is used; with plain JSON.parse they are strings.

Format the result with the Flow Formatter. For TypeScript projects, JSON to TypeScript generates the equivalent interfaces. Generation runs in your browser.

Frequently asked questions

Do the generated Flow types check data at runtime?
Type aliases do not. Leave Types only off to get a Convert module that validates the JSON structure when parsing.
Why does the file start with // @flow?
Flow only checks files that contain the @flow pragma (unless your configuration says otherwise), so the generator adds it.
How do I allow a field to be null or a string?
Use a maybe type such as ?string, which accepts string, null and undefined.
Is the output compatible with TypeScript?
The object type syntax is similar, but files contain Flow-specific pragmas and export syntax. Use JSON to TypeScript for TypeScript projects.
When should I tick “Types only (no helpers)”?
Tick it when you only need the type aliases, for example to annotate data that is already validated elsewhere, or to paste types into an existing module. Leave it off if you want the generated Convert functions, which check the shape of API responses at runtime and fail early with a clear error instead of letting bad data spread through your app.
How do I name the generated root type?
Enter a name in Top-level class name, such as Order. Nested objects get names derived from their property keys, so an owner object becomes Owner. If two properties would produce the same name, rename one type by hand after generation and update the references.

Last updated September 26, 2026

Related tools

XML to Flow Generate Flow Flow type definitions from a XML sample instantly, with nested types detected automatically. JSON to Go Generate Go structs with json tags from a JSON sample instantly, with nested types detected automatically. JSON to Haskell Generate Haskell records with Aeson instances from a JSON sample instantly, with nested types detected automatically. JSON to Java Generate Java POJO classes with getters and setters from a JSON sample instantly, with nested types detected automatically. JSON to JavaScript PropTypes Generate JavaScript PropTypes React PropTypes definitions from a JSON sample instantly, with nested types detected automatically. JSON to JSON Schema Generate JSON Schema a JSON Schema document from a JSON sample instantly, with nested types detected automatically. JSON to Kotlin Generate Kotlin data classes from a JSON sample instantly, with nested types detected automatically. JSON to Laravel Model & Migration Generate a Laravel Eloquent model ($fillable, casts, relations) and a matching migration from a sample JSON record. JSON to Mongoose Schema Generate a Mongoose schema and model from a sample JSON document, detecting Date, ObjectId, arrays and nested objects. JSON to Objective-C Generate Objective-C classes with properties from a JSON sample instantly, with nested types detected automatically. JSON to PHP Generate PHP classes with typed properties from a JSON sample instantly, with nested types detected automatically. JSON to Pike Generate Pike classes from a JSON sample instantly, with nested types detected automatically.