I'm making webapi using .net core 2.2
. And I'm new to .net framework So far I was working with javascript based frameworks like nodejs expressjs.
It's easy to customize JSON response in nodejs. Can you exaplain how to customize the JSON response with .NET Core 2.2 WebApi? Just point me to right direction.
Let me give an example,
C# User Model
public class User {
int id {get;set;}
string name {get;set;}
string username {get;set;}
string password {get;set;}
}
Default API Get Reponse.
public ActionResult<IEnumerable<User>> GetAll()
Json:
[
{
"id":1,
"name": "John Doe",
"username": "john",
"password": "AH7B302Iapxf7EFzZVW0/kJDuf/I3pDPkQ42IxBTakA="
},
{
"id":2,
"name": "Jane Doe",
"username": "jane",
"password": "AH7B302Iapxf7EFzZVW0/kJDuf/I3pDPkQ42IxBTakA="
}
]
I need to customize the output like this.
{
"statuscode": 200,
"count" : 2,
"data" :
[
{
"name": "John Doe",
"username": "john",
},
{
"name": "Jane Doe",
"username": "jane",
}
]
}