Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

liulei237136's avatar

how can php convert json to php array

is there some good library

0 likes
7 replies
jlrdw's avatar

It's documented in the PHP manual.

1 like
devSSI's avatar

Hi,

first make sure you are getting correct JSON, and after that proceed with

$data = json_decode(your-json, true)

  • First parameter is the JSON you want to convert to the array
  • Second parameter "true" means you want associative array, if you don't want it then just ignore this param

Dump $data

Good luck!

1 like
devSSI's avatar
devSSI
Best Answer
Level 5

@liulei237136 No probs :)

If this helped you, could you please mark it as a best answer so the others can find it too?

Thanks

1 like
monahmad's avatar

$json_data = '{"name": "John", "age": 30, "city": "New York"}';

// Convert JSON data to PHP array $php_array = json_decode($json_data, true);

// Check if decoding was successful if ($php_array !== null) { // Now $php_array contains the converted JSON data var_dump($php_array); } else { // Handle the case where decoding failed echo "JSON decoding failed!"; }

Please or to participate in this conversation.