One-click convert JSON data to PHP class definitions with typed properties, constructors, and getters/setters
Zero Dependencies · Works Offline📝 JSON Input
What is JSON to PHP Class Converter?
The JSON to PHP Class Converter is a free online developer tool that instantly converts JSON data into PHP class definitions. It automatically identifies JSON field types and maps them to PHP types, supporting nested object class generation, PHP 8 named argument constructors, typed property declarations, and getter/setter method generation. Perfect for Laravel/Symfony developers who need to quickly generate model classes from API responses, dramatically reducing manual PHP class writing. All conversion happens locally in your browser — no data is ever uploaded to a server.
Core Features
- Smart Type Mapping: Auto-detects string→string, number→int/float, boolean→bool, array→array, null→nullable types
- Nested Classes: Nested JSON objects are automatically generated as separate PHP class definitions
- Constructors: Supports PHP 8 named argument constructors or PHP 7 traditional constructors
- Getter/Setter: Optionally generate getter and setter methods for business logic extension
- Multi-Version: Supports PHP 8.x, 7.4+, and 7.x syntax variants
How to Use
1. Paste your JSON data into the input area, or click "Load Example" to try it quickly.
2. Set the class name and conversion options: PHP version, constructor, getter/setter, etc.
3. Click "Convert" or use Ctrl+Enter to execute.
4. View the generated PHP class code in the result area below.
5. Click "Copy Code" to copy to clipboard, or download as a .php file.
Use Cases
Laravel Models
When integrating APIs, paste JSON responses to instantly generate Eloquent model or DTO classes for Laravel projects.
Symfony Entities
Quickly generate entity classes from JSON Schema with Symfony, combined with ORM annotations for faster development.
API Clients
PHP backend developers calling third-party APIs can generate type-safe response classes from JSON responses.
Config Mapping
Map JSON configuration files to PHP classes for type-safe configuration access.
Technical Background
PHP 7.4 introduced typed properties, allowing type specification in property declarations. PHP 8.0 enhanced the type system with union types (e.g., int|string) and named arguments for clearer constructor calls. PHP 8.1 added enums, and PHP 8.2 supports readonly classes. In Laravel, Eloquent models typically use the $casts property for JSON field type conversion. The DTO (Data Transfer Object) pattern is increasingly popular in PHP for passing type-safe data between layers.
âť“ FAQ
Does it support nested JSON?
Yes. Nested objects are automatically generated as separate PHP class definitions.
How are null values handled?
With "Nullable types" enabled, null fields generate nullable types (e.g., ?string).
Which PHP versions are supported?
PHP 8.x (named args + typed props), PHP 7.4+ (typed props), and PHP 7.x (traditional syntax).
Is my data uploaded?
No. Everything runs locally: JSON to PHP Class and other values are processed on your device, never sent to a server. Your data never leaves your device.
Can it generate getters and setters?
Yes. Enable the Getter/Setter option to generate corresponding methods.
Can generated code be used directly?
Yes. The output follows PSR standards and can be copied directly into a .php file.