Home  »  CodeLibrariesProgrammingSnippetsTechnologyTools   »   PHP Parse JSON Code

PHP Parse JSON Code

Posted: March 15, 2022 | by Michael Bright

PHP parse JSON code example.

$json = '{ "name":"John Denver", "title":"Marketing Director" }';

$person = json_decode( $json );

echo $person->name; // John Denver

echo $person->title; // Marketing Director

// use this to returned an associative array:

$data = json_decode( $json, true );

echo $data["name"]; // John Denver

echo $data["title"]; // Marketing Director

PHP decode JSON file.

$json = json_decode( file_get_contents( '/path/to/your/file.json' ) );

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.