Convert XML to JSON

Convert XML to JSON

Recently, we started using a new vendor at work. This particular vendor still uses XML for their API endpoints. I don’t particularly like working with XML in PHP, so I converted it JSON which is much easier to work with.

$xml = simplexml_load_string((string)$guzzle_response->getBody());
$json = json_encode($xml);
$json = str_replace('{}', null, $json);
$response = json_decode($json);


Leave a Reply

Your email address will not be published. Required fields are marked *