How to Parse Json in PHP

Once again php shows how it is an easy language for beginners. In PHP you don’t have to think about much when you want to parse json. Json parsing and encoding has been part of the core php language for several version now - and before that as an extension with the exact same methods.

The only real decision you need to make is wether to get your data back as objects or associative arrays - most php users choose the latter - even though it is not the default from the json_decode method:

<?php
$jsonString = '{"name": "Claus Witt"}';
$data = json_decode($jsonString, true);
echo $data['name'];

Related Posts