$myArray = array('name' => 'John', 'age' => 30, 'isMarried' => true); $jsonString = json_encode($myArray); // convert array to JSON
class Person { public $name; public $age; public $isMarried; } $person = new Person(); $person->name = 'John'; $person->age = 30; $person->isMarried = true; $jsonString = json_encode($person); // convert object to JSONThese examples demonstrate how to use the Util toJSON function in PHP to convert data to JSON format. The package library used for this function is the built-in PHP JSON extension.