You should have a look at this really complete blog post : http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/
William Durand talks about how to create a good REST Api and about JSON response with the correct status code.
If you are following what William wrote in his article, you will have a JSON response based on this format :
{
code: 400,
message: "Your message",
first_data: "...",
second_data: "...",
...
}
Which is not exactly what you are looking for. But I think the code your clients will have to write will be as simple as what you want with the format you proposed :
{
meta: {
code: 400,
message: 'Your request failed because...',
}
data: {}
}
Maybe you can show what you did in your controller so my answer could be more precise.
Update:
With the following controller, you should be able to return the JSON Response you want :
use Symfony\Component\HttpFoundation\JsonResponse;
class MyController{
//...
public function myAction(){
$myStatusCode = 400;
return new JSonResponse(
array('meta' => array('code' => $myStatusCode,
'message' => 'Your request failed because...'),
'data' => array('your datas')
),
$myStatusCode
);
}
//...
}
This will create a response with the correct status code in the header and it allows you to add the message and status code you want in your JSon response.