MVC4 web api returns json in this format:

 {
      "LastLoginTime": "2012-07-14T13:17:36.1268831-07:00",
      "UserId": 1,
      "Email": "[email protected]",
      "FirstName": "John",
      "LastName": "Smith"
 }

which is just a serialization of the object model.

I need to return and accept json with a root object and a JsonResult object. Something like this (imagine a login attempt to an api):

{
"data": [
    {
        "success": false,
        "exception": {
            "message": "Either the email address does not exist or th epassword is incorrect"
        }
    }]
}

or for a successful authentication

{
"data": [
    {
        "success": true,
        "account": {
            "LastLoginTime": "2012-07-14T13:17:36.1268831-07:00",
            "UserId": 1,
            "Email": "[email protected]",
            "FirstName": "John",
            "LastName": "Smith"
        }
    }]
}

How would I go about that using a custom implementation of MediaTypeFormtatter that is used in MVC4 webapi (RC) that will allow me to format my results in the way I described?

share|improve this question
I modified your JSON to be a easier to read, but I can't tell if your second example is an object or an array because it starts and ends with different symbols. – Erik Philips May 17 '12 at 5:20
I guess what I am trying to do is have the object always called/wrapped inside data. (Edited the second example to make it more clear (I hope!)) – George D. Jun 6 '12 at 3:19

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.