In this tutorial, We will learn how to convert XML to JSON data in PHP.


Example:

<?php
  
    $xmlObject = simplexml_load_file('sample.xml');
    $jsonData = json_encode($xmlObject, JSON_PRETTY_PRINT);
      
    print_r($jsonData);
?>


Thanks, I hope it will help you...