Skip to main content


Showing posts from July, 2023

Migrating An API from Newtonsoft.Json to System.Text.Json

In some recent work with Umbraco I’ve been looking to migrate an API from using the Newtonsoft.Json serialization library to the newer, Microsoft one, System.Text.Json . The reason for doing this was to align the API we created for Umbraco Forms with the content delivery API available in Umbraco 12. We’re keen to ensure these APIs across Umbraco products are similar both in terms of behaviour but also behind the scenes when it comes to the libraries we are using. As such I had a few updates to make – mostly straightforward, and some that needed a bit more research and development. Deserialization via a Model Binder When a form is submitted, a model binder is referenced in the controller’s action method to deserialize the incoming request to a strongly typed model: Within the model binder we had the following code to deserialize the request into the appropriate type: To convert this it was just necessary to change JsonConvert.DeserializeObject to JsonSerializer.Deser