Skip to main content

JSON to PHP Array — Associative & Indexed, Short [] or array(), Zero Upload

JSON to PHP array — paste JSON, get a clean associative or indexed array with short [] or array() syntax, 2/4 indent, trailing comma, and an optional <?php return …; wrapper.

  • Runs locally
  • Category Developer & DevOps
  • Best for Formatting, validating, shrinking, or inspecting code-adjacent text.
Examples:
How JSON maps to a PHP array

A JSON object becomes a PHP associative array — every key is emitted as a single-quoted string in `'key' => value` form, which is the safe choice because a JSON key is always a string and PHP would otherwise coerce a numeric key like "0" to the integer 0. A JSON array becomes a plain indexed array. Strings are single-quoted with only `\` and `'` escaped (PHP single-quote rules — `\n` stays a literal backslash-n, not a newline). Integers and floats render bare, `true`/`false`/`null` map straight across, and an empty object or array both render as `[]`. Toggle short `[]` vs legacy `array()`, switch indent between 2 and 4 spaces, add a trailing comma (Git-diff friendly), and wrap the whole thing in `<?php return …;` to get a drop-in Laravel config or seeder file.

What this tool does

Paste any JSON — a Laravel config dump, a WordPress option, an API payload, a row of seed data — and get back a clean PHP array literal you can drop straight into a `.php` file. A JSON object becomes a PHP associative array (`'key' => value`); a JSON array becomes an indexed array. Keys are always emitted as single-quoted strings, which is the safe choice: a JSON key is always a string, so a numeric-looking key like `"0"` stays `'0'` instead of being silently coerced to the integer `0` the way an unquoted PHP key would. Strings are single-quoted with only `\` and `'` escaped — exactly PHP's single-quote rules — so a Windows path like `C:\Users\dev` and an apostrophe like `it's` come out correct instead of mangled. Integers and floats render bare, `true` / `false` / `null` map straight across, and empty objects and arrays both render as `[]`. Toggle modern short `[]` against legacy `array()` (handy for codebases stuck on PHP 5.3), switch the indent between 2 and 4 spaces to match your coding standard, add a trailing comma for clean Git diffs, and wrap the whole thing in `<?php return …;` to get a drop-in config or seeder file. Share the exact input and options as a link, copy the result, or download it as a `.php` file. Everything runs in your browser — the JSON never touches a server.

Tool details

Input
Text + Numbers + Structured content
The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
Output
Live result + Copy + Download
The result area focuses on usable output, with copy, download, or preview actions when supported.
Privacy
Browser-side processing
The main tool logic does not call an external API, so inputs normally stay in the current tab.
Save / share
Shareable URL state
Key settings are encoded in the URL so another person can reopen the same setup.
Performance budget
Initial JS <= 22 KB
No WASM budget is declared, keeping the tool quick to open on mobile.
Best fit
Developer & DevOps · Developer
Category and role tags drive related tools, internal links, and quick fit checks.

How to use

  1. 1. Input

    Paste or drop your content into the tool panel.

  2. 2. Process

    Click the button. All processing is local in your browser.

  3. 3. Copy / Download

    Copy the result or download to disk in one click.

How JSON to PHP Array fits into your work

Use it in the small gaps between coding, reviewing, debugging, and shipping.

Developer jobs

  • Formatting, validating, shrinking, or inspecting code-adjacent text.
  • Preparing snippets for documentation, tickets, commits, or handoff.
  • Checking a small payload quickly without switching tools.

Developer checks

  • Run irreversible transforms like minify or obfuscate on a copy.
  • Keep secrets out of pasted snippets unless the tool explicitly stays local.
  • Use your normal tests or linter before shipping transformed code.

Good next steps

These links move the current task into a more complete workflow.

  1. 1 JSON to Go Struct JSON to Go struct — paste JSON, get typed structs with json tags, exported fields, nested sub-structs, pointers for nullable, int64 and omitempty options. Open
  2. 2 JSON to TypeScript Interface JSON to TypeScript interface — paste JSON, get clean interfaces with union types from arrays, optional vs required detection, root name customizable. Open
  3. 3 JSON Formatter & Validator Format, validate, and minify JSON instantly — right in your browser. Open

Real-world use cases

  • Turn a JSON config into a Laravel config file

    A third-party package ships its defaults as a JSON blob, but your Laravel app wants a `config/service.php` that returns an array. Paste the JSON, turn on the `<?php return …;` wrapper, leave short syntax on, set indent to 4 to match Laravel's style. Copy the output into `config/service.php`, and `config('service.host')` resolves at runtime exactly as the package author intended — no hand-typing 40 keys and risking a typo'd `'tiemout'`.

  • Seed a database table from captured JSON rows

    You have a JSON array of 20 sample records from an API and want them in a `DatabaseSeeder`. Paste the array, turn on trailing commas (so adding a row later is a one-line clean diff), and drop the result into `DB::table('products')->insert([ … ]);`. The apostrophe in `"O'Brien"` comes out as `'O\\'Brien'` already escaped, so the seeder runs without a parse error on the first try.

  • Migrate a WordPress option stored as JSON

    A plugin saved its settings as a JSON string in `wp_options`. You're writing a migration that needs the same data as a native PHP array for `update_option()`. Paste the JSON, keep short syntax, copy the `[ … ]` literal straight into your migration function. The numeric keys stay quoted (`'0' =>`) so `update_option` stores them as you expect instead of reindexing.

  • Build a fixture for a PHPUnit test

    Your test needs a representative payload as a PHP array to feed a service mock. Curl the real endpoint, paste the JSON response here, leave the wrapper OFF (you're pasting into the middle of a test method), and copy the bare `[ … ]` into `$expected = [ … ];`. Now your assertion compares against a literal that mirrors production, not a hand-summarised approximation.

  • Convert API docs JSON examples to PHP SDK snippets

    You're writing PHP SDK documentation and the upstream API docs give request bodies as JSON. Paste each example, get the PHP array form, and embed it in your `$client->post('/orders', [ … ])` snippet. Indent at 4 spaces to match your docs' code blocks, and every example is consistent instead of one dev using `array()` and another using `[]`.

Common pitfalls

  • Expecting an empty JSON object {} to round-trip back to an object. Both {} and [] render as [] because PHP has no distinct empty-map literal — once it's `[]`, PHP treats it as an indexed array. If a downstream consumer must see an associative shape, you'll need at least one key, or cast it explicitly with `(object)` in your PHP.

  • Assuming \n in a string becomes a newline. We emit single-quoted PHP strings, where `\n` is a literal backslash followed by n — NOT a line break. That's correct PHP single-quote behaviour. If you actually need real newlines in the value, the JSON should contain an actual newline character (which renders verbatim inside the single quotes), not the two characters backslash-n.

  • Hand-editing a numeric key to drop the quotes. The tool emits `'0' => …` on purpose: a JSON key is always a string. If you manually change it to `0 => …`, PHP coerces it to the integer key 0, and a subsequent `'0'` string-key lookup may miss. Leave the quotes unless you specifically want integer keys.

  • Pasting JSON5 / JSON-with-comments / trailing commas in the INPUT. We use strict `JSON.parse`, so comments, unquoted keys, and trailing commas in your *input* all error out (the trailing-comma option only affects the PHP *output*). Strip them first or run the input through a JSON formatter.

Privacy

Your JSON never leaves this browser tab. Parsing and rendering use the browser's built-in `JSON.parse`; there is no network call and no analytics on the textarea content. The Share link encodes your input and option choices into the URL so a result is reproducible — that means YOU decide when to share. If the payload is sensitive (config with API keys, DB credentials, customer data), copy the generated PHP instead of sharing the link. Only your option choices (short syntax / indent / trailing comma / return wrapper) are stored in localStorage so your preferred style persists across visits.

FAQ

Tool combos

Folks in your role tend to reach for these alongside this tool.

Made by Toolora · 100% client-side · Updated 2026-06-12