Skip to content

JSON to PHP Array

Convert JSON into a PHP array literal or a typed class you can paste into a project.

Output

Quick Tool Overview

The JSON to PHP Array converter writes a PHP array literal with the modern short syntax, correctly indented and escaped, or typed PHP 8 classes with promoted constructor properties if you want real models instead.

What it does
Converts JSON into a PHP array literal or typed classes
You give it
Any JSON document
You get back
PHP source you can paste into a project
Best for
Config files, seeders, test fixtures and typed models
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the JSON to PHP Array

Two things people mean by "JSON to PHP", and this tool does both. The array mode writes a PHP array literal with the modern short syntax, correctly indented and with strings escaped, so it can be pasted straight into a config file, a seeder or a test fixture.

The class mode writes typed PHP 8 classes instead, using promoted constructor properties, with a nullable type and a null default for any field that is not always present. Nested objects become their own classes and arrays carry an array-shape docblock, which is what static analysers such as PHPStan and Psalm need in order to check the code that consumes them.

Key features of the JSON to PHP Array

Two output modes

An array literal for fixtures and config, or typed PHP 8 classes with promoted constructor properties for models.

Short or long syntax

Emit [1, 2, 3] or array(1, 2, 3) depending on how old the codebase you are pasting into is.

Correct escaping

Quotes and backslashes inside string values are escaped, so the literal parses on the first try.

Types the analysers understand

Class mode adds array-shape docblocks, which is what PHPStan and Psalm need to check the code around them.

Nullable where it matters

Fields that are not always present are typed nullable with a null default, so constructing the object never fails on a partial payload.

How to use the JSON to PHP Array

  1. 1

    Paste your JSON

    Any document, from a small config object to a full API response.

  2. 2

    Pick array or class output

    Array for fixtures and config; classes for typed models.

  3. 3

    Set the formatting

    Choose short or long array syntax and the indentation width.

  4. 4

    Copy into your project

    Paste the result into a .php file, or download it.

Frequently asked questions

For runtime data you should. This is for the times you want the data in the source itself — a config file, a seeder, a test fixture, or a typed class that gives your IDE and static analyser something to work with.

Reviews of the JSON to PHP Array

What people who use the JSON to PHP Array think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the JSON to PHP Array. It takes half a minute and no account.

Write the first review

More developer tools