JSON Input

Flow Output

What Is JSON to Flow Type Generator?

Flow is a static type checker for JavaScript developed by Meta. It uses type annotations, written in a syntax close to TypeScript's, to catch type errors before your code runs. This generator reads a JSON sample and writes Flow export type aliases that describe its shape, ready to drop into a file with the // @flow pragma.

Unlike TypeScript, Flow runs on ordinary JavaScript files marked with // @flow, and Babel strips the annotations at build time, which suits teams adding types gradually. A few rules the generator follows: every nested object gets its own named type; array items are merged across all elements, so a key that only some items have becomes optional (note?: string); a value that is null in some samples becomes a maybe type (?string); keys that aren't valid identifiers, like first-name, are quoted. A value that is only ever null becomes mixed, since one sample can't tell what it really holds.

How to Convert JSON to Flow Types

Follow these three steps to generate Flow type definitions from your JSON data.

1

Paste or Upload JSON

Paste your JSON into the left panel, or click Sample to see an example. Set the Root Type Name if you want something other than RootObject. Flow types appear in the right panel as you type.

2

Review the Generated Flow Types

The right panel shows export type declarations, with nested types listed before the types that use them. Arrays become Array<T>, optional keys get a ? after the name, and nullable values get a ? before the type.

3

Copy or Download

Click Copy to send the types to your clipboard, or Download to save a .js.flow file. The output already starts with // @flow and exports every type, so other files can import type { RootObject } from './rootobject'.

Common Use Cases

React & React Native Apps

Flow is widely used in React and React Native projects. Generate prop types and state types directly from your API response JSON to add compile-time safety without migrating to TypeScript.

API Response Typing

When integrating a third-party REST API, paste a sample response and get Flow types instantly. This eliminates hand-authoring verbose type declarations and reduces human error.

Legacy JavaScript Migration

Incrementally add Flow types to a large legacy JavaScript codebase. Generate types from JSON config files or data fixtures to bootstrap type coverage file by file.

Configuration File Typing

Complex JSON configuration files — build configs, feature-flag configs, app settings — can be typed with Flow so that any misconfiguration is caught before reaching production.

Frequently Asked Questions

How does Flow compare with TypeScript?

Both are JavaScript static-type systems. Flow is a checker that annotates plain JS files via a pragma; TypeScript is a compiled superset of JS. Flow types are stripped by Babel at build time. TypeScript has broader ecosystem support, while Flow is still preferred by some Meta-stack teams.

Are exact object types generated?

Yes, in the sense that matters today. Since Flow 0.202, plain { ... } object types are exact by default, so the generated types reject unexpected properties. If you're on an older Flow version or want inexact types, add ... at the end of an object type. See the Flow object type docs for details.

How are arrays handled?

Arrays are typed as Array<T>. For arrays of objects, every element is inspected and their keys are merged into one item type. Mixed arrays get a union, like Array<string | number>. Empty arrays produce Array<mixed>, since there's nothing to infer from.

Does my JSON leave my browser?

No. All processing happens entirely in your browser. Your JSON data is never sent to any server.

Can I use the output directly in my project?

Yes. Copy the types into a .js.flow file or a regular JS file that starts with // @flow. Treat them as a first draft: a sample only shows the values it contains, so you may want to tighten mixed fields or rename types to match your codebase.

Related Tools

Explore other JSON conversion and validation tools on jsonparser.ai.