FormatterHQ

JSON to JavaScript PropTypes

Generate React PropTypes shapes from sample JSON props. Nested objects become PropTypes.shape and arrays become PropTypes.arrayOf.

Input JSON
Output JAVASCRIPT
Ready.

How to use the JSON to JavaScript PropTypes

  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 TaskShape; it is converted to PascalCase. Nested types are named after their property keys.
  3. The Types only option does not change the PropTypes output.
  4. Press Generate (it also re-runs automatically as you edit), then use Copy or Download.

JSON to PropTypes for React components

PropTypes add runtime checks to React component props in plain JavaScript projects: in development, React logs a warning when a prop has the wrong type. Describing a deep data prop by hand with PropTypes.shape is tedious, so this JSON to PropTypes generator builds the shapes from example data, such as an API response you pass to a component.

Example

{ "id": 42, "title": "Write docs", "done": false,
  "owner": { "name": "Ada", "email": null },
  "subtasks": [ { "title": "Outline", "estimate": 2 }, { "title": "Draft" } ] }
import PropTypes from "prop-types";

let _Task;
let _Owner;
let _Subtask;
_Subtask = PropTypes.shape({
    "title": PropTypes.string,
    "estimate": PropTypes.oneOfType([PropTypes.number, PropTypes.any]),
});
_Owner = PropTypes.shape({
    "name": PropTypes.string,
    "email": PropTypes.any,
});
_Task = PropTypes.shape({
    "id": PropTypes.number,
    "title": PropTypes.string,
    "done": PropTypes.bool,
    "owner": _Owner,
    "subtasks": PropTypes.arrayOf(_Subtask),
});

export const Task = _Task;

Use it on a component like this:

import { Task } from "./taskShape";

TaskCard.propTypes = {
    task: Task.isRequired,
};

How JSON types map to PropTypes

Numbers of any kind become PropTypes.number, strings PropTypes.string, booleans PropTypes.bool, nested objects a separate PropTypes.shape, and arrays PropTypes.arrayOf(...). When an array mixes types, for example numbers and strings, the element validator becomes PropTypes.oneOfType([PropTypes.number, PropTypes.string]). Shapes are declared first and assigned afterwards, which allows nested and even recursive shapes to refer to each other. The file exports the top-level shape as an ES module, ready to import into a component.

How to refine the shapes

  • Required props: the generated validators are optional. Add .isRequired to fields the component cannot render without, such as title.
  • Optional values like estimate are typed as oneOfType([number, any]); simplify to PropTypes.number, which already accepts undefined.
  • Fixed values: replace PropTypes.string with PropTypes.oneOf(["open", "closed"]) for status fields.
  • Dates in JSON are strings, so they are validated as PropTypes.string.
  • exact instead of shape makes React warn about unexpected keys.

PropTypes today

PropTypes checks run only in development builds. React 19 no longer checks propTypes on components, and many projects have moved to TypeScript for compile-time checking. For existing JavaScript code bases on earlier React versions, PropTypes remain a lightweight safety net. If you are migrating, JSON to TypeScript produces interfaces from the same sample, and JSON to Flow covers Flow-typed code. Generation runs in your browser.

Checking data outside a component

The generated shapes are ordinary validators, so you can also check a value by hand, for example an API response in a test or a data-loading function. The prop-types package exposes checkPropTypes for this:

import PropTypes from "prop-types";
import { Task } from "./taskShape";

PropTypes.checkPropTypes(
    { task: Task.isRequired },
    { task: responseData },
    "prop",
    "TaskLoader"
);

Mismatches are logged with console.error, naming the property path, just like component warnings. The check runs only in development builds and does nothing in production, so it is a debugging aid rather than input validation. On React 19, where components no longer check propTypes, this manual call is the way to keep using existing shapes.

Frequently asked questions

Do PropTypes work in production?
No. React only checks PropTypes in development builds, so they help catch mistakes while developing without costing performance in production.
Does React 19 still support PropTypes?
React 19 removed propTypes checking from components. The prop-types package still works for manual checks, but TypeScript is the common replacement.
Why aren’t my props marked isRequired?
A sample cannot show which props a component needs. Add .isRequired to the props your component depends on.
What is the difference between shape and exact?
PropTypes.shape allows extra keys; PropTypes.exact warns when an object has keys that are not listed.

Last updated September 26, 2026

Related tools

XML to JavaScript PropTypes Generate JavaScript PropTypes React PropTypes definitions from a XML 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. JSON to Python Generate Python dataclasses with type hints from a JSON sample instantly, with nested types detected automatically. JSON to Ruby Generate Ruby Dry::Struct classes from a JSON sample instantly, with nested types detected automatically. JSON to Rust Generate Rust structs with Serde derives from a JSON sample instantly, with nested types detected automatically. JSON to Scala Generate Scala case classes from a JSON sample instantly, with nested types detected automatically.