Reputation: 303
I need this type of json response in PHP
{
"errors": [
{
"message": "Something went wrong!"
}
]
}
Where "errors" is an array, and "message" is encoded in json
If I encode it something like this
json_encode (['errors' => ['message' => 'Unauthenticated.']])
it prints like
{
"errors": {
"message": "Unauthenticated."
}
}
but I want it like above, any proper solution for this?
Upvotes: 2
Views: 106
Reputation: 163
You could do it like this:
json_encode(['errors' => [['message' => 'Unauthenticated.']]]);
output:
{
"errors": [
{
"message": "Unauthenticated."
}
]
}
Upvotes: 1