Reputation: 171
how do i create a json object similar to this in PHP?
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
Upvotes: 9
Views: 17373
Reputation: 66170
You create an array, and pass it to json_encode
$stuff = array(
'employees' => array(
array('firstName' => 'John', 'lastName' => 'Doe'),
....
)
);
echo json_encode($stuff);
Upvotes: 24