9

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" }
    ]
}
0

1 Answer 1

24

You create an array, and pass it to json_encode

$stuff = array(
    'employees' => array(
        array('firstName' => 'John', 'lastName' => 'Doe'),
        ....
    )
);

echo json_encode($stuff);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.