Go JSON config file

Seems there’s no standard or official way to load configuration files in Go. There are libraries out there, but if you’re just looking for something simple, you’d just read a JSON file into your application. config/configuration.go config/email.go conf.json main.go

Type-safe JSON result in ASP.NET MVC

public abstract class BaseController : Controller { protected internal JsonResult<T> Json<T>(T data) { return Json(data, null /* contentType */, null /* contentEncoding */, JsonRequestBehavior.DenyGet); } protected internal JsonResult<T> Json<T>(T data, string contentType) { return Json(data, contentType, null /* contentEncoding */, JsonRequestBehavior.DenyGet); } protected internal virtual JsonResult<T> Json<T>(T data, string contentType, Encoding contentEncoding) { return Json(data, […]

JSON infinite loops in ASP.NET

If you accidentally (or purposely) have an infinite loop in an object, where it has a reference that points back to itself, when you try to return that object as JSON in ASP.NET, you get an error: JsonSerializationException: Self referencing loop detected for property… To avoid that, you can add a line to your Startup […]

ASP.NET JSON Self Referencing Properties

In object-oriented languages, an object can hold a reference to itself in a property, and there’s no problem with that. However, when you go to serialize that object, you run into issues. An object with a self-referencing property that loops back to itself would cause an infinite loop and crash when trying to serialize it. […]

JSON casing in ASP.NET Core

Some mallethead decided that they wanted to take UpperCamelCase names of properties and change them to lowerCamelCase when sending JSON to the client. Sure, maybe this fits standard naming conventions, but it means that you’ll end up with different property names. public JsonResult GetFoo() { return Json(new Foo { Name = “Jane Doe”, Age = […]