DEV Community

Cover image for JSON and C# : Syntax Differences
John Peters
John Peters

Posted on

JSON and C# : Syntax Differences

Assume we have a bit of JSON that looks like this:

{
  title: "The lowly Interface",
  url: "https://dev.to/xyz"
},
Enter fullscreen mode Exit fullscreen mode

This is the C# equivalent


var responseMessage = 
new { 
 title = "The lowly Interface", 
 url = "https://dev.to/xyz" 
};

Enter fullscreen mode Exit fullscreen mode

This mismatch in syntax is the 'new' keyword, and the replacement of ':' with '='.

If we return the responseMessage using Azure Functions like this:

return new OkObjectResult(responseMessage);
Enter fullscreen mode Exit fullscreen mode

The client side browser will receive this information.

{
 title: "The lowly Interface", 
 url: "https://dev.to/xyz"
}
Enter fullscreen mode Exit fullscreen mode

This is why it's better to use a no-sql database instead of this construct; except when one-off responses are needed.

Top comments (0)