JSON to PHP Converter
Convert JSON to PHP POJO classes for PHP development
JSON Input
PHP Output
What Is JSON to PHP?
PHP uses json_decode() to parse JSON into arrays or objects. For typed access, you often want classes. This tool generates PHP class definitions from your JSON. Use them with json_decode() and manual mapping, or with json_encode() for serialization. The PHP JSON extension is built in. PHP 7.4+ typed properties and 8.0+ attributes improve type safety.
Conversion runs in your browser. Set the class name and namespace in the config. Toggle Typed Properties and Nullable. Nothing is sent to a server.
How to Use This Tool
Paste JSON
Paste your JSON or upload a file. Set class name and namespace in the config. Enable Typed Properties for PHP 7.4+ type hints.
Review the Classes
The right panel shows generated PHP classes. Nested objects become separate classes. Arrays get array or array<Type>. Use json_decode($str, false) for objects, or map to your classes.
Copy or Download
Use Copy or Download. Paste into your project. For formatting JSON first, use the JSON Formatter. For validation, use the JSON Validator.
JSON to PHP Examples
Here is an example of generating PHP classes from a JSON object.
Example: Subscriber record
JSON input:
Generated PHP output:
When JSON to PHP Helps
When integrating REST APIs in Laravel, WordPress, or plain PHP, you often need typed classes for API responses. Pasting a sample response here gives you PHP classes you can use with json_decode() and manual mapping. For API testing, Postman helps. Webhook payloads, config files, and database exports that are JSON benefit from the same treatment. For pulling out specific values from large responses first, use the JSON Path tool.
Frequently Asked Questions
Typed properties?
PHP 7.4+ supports typed class properties. Enabling this gives you public string $name; instead of untyped. Requires PHP 7.4 or later.
What about camelCase vs snake_case?
PHP often uses snake_case; JSON APIs use camelCase. The generator uses JSON keys as-is. Add custom logic or use a library that maps keys.
Is my data sent anywhere?
No. Generation runs in your browser.
Nullable types?
Enable for optional fields. PHP 7.1+ supports ?Type for nullable. Useful when JSON can omit a field.
Can I use this with Laravel?
Yes. The generated classes work anywhere. Laravel's Eloquent uses different patterns; for API responses, these DTOs are fine. See the MDN JSON guide for format details.
Related Tools
PHP JSON. json_decode(). JSON spec. RFC 8259. MDN. Laravel. Postman.