Alex's Coding Blog
  • home
  • about
  • projects
  • contact

Blog

Replace the default Azure Function Json pascalCase formatter with camelCase

  • July 19, 2021
  • by Alexander

I use dotnet-isolated function runtime and by default it is using ObjectSerializer to convert objects to Json. The response is formatted with PascalCase which is doesn't look as natural Json naming style. Let's see how we can format it to camelCase and remove nullables.

{
    "Errors": []
}

I didnt find a way how to configure the serializer for the function on global level, however it quite simple to set the serilizer while writing the response.

The following code example creates a new response and writes an object

var response = req.CreateResponse(HttpStatusCode.Created);
await response.WriteAsJsonAsync(new MyClass());

First, ObjectSerializer is one of the optional parameters for the WriteAsJsonAsync extension method, which can be replaced with one from Newtonsoft.Net. ObjectSerializer is part of Azure.Core.Serialization to user its Newtonsoft.Net implementation, you have to install Microsoft.Azure.Core.NewtonsoftJson package.

Secondly, you need to create settings for JsonSerializer:

var s = new JsonSerializerSettings
{
    NullValueHandling = NullValueHandling.Ignore,
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

var serializer = new NewtonsoftJsonObjectSerializer(s);

And the last one, use defined serializer while writing the response

await response.WriteAsJsonAsync(new MyClass(), serializer);

The response is formatted with camelCase

{
    "errors": []
}
Azure Functions

🚀 Turbocharge Your Kubernetes Cluster with my Terraform Kits! 🚀

🌟 Slash deployment time and costs! Discover the ultimate solution for efficient, cost-effective Kubernetes Terraform Kits. Perfect for DevOps enthusiasts looking for a reliable, scalable setup.

Learn More about Terraform Kits for AKS,EKS and GKE

Alexander Lvovich

Solution Architect & Software Developer | Automating & Scaling Infrastructure

💡 Working with Kubernetes, Istio, and DevOps. Got questions? Feel free to reach out!

Share on:

No comments are allowed for this post

Recent Posts

  • Securing Web Services Against Unwanted Traffic with NGINX
  • Optimizing API by Offloading Responsibilities to an API Gateway
  • How to Clean Up Local Branches of Remote Merged Branches
  • Resolving Namespace Overriding in Argo CD with Kustomize
  • Connecting to Gitlab's private Nuget registry
  • Why Istio?

Categories

  • Azure
  • Architecture
  • .NET Core
  • Certification
  • DevOps
  • How-to
  • Azure Functions
  • Serverless
  • Cosmos DB
  • Security
  • Thoughts
  • Kubernetes
  • Istio
© Copyright 2025, Alexander Lvovich. Theme by Colorlib
I use cookies and similar technologies on our website to enhance your browsing experience and analyze website traffic. By clicking "Accept," you consent with my Privacy Policy to the use of these technologies.
Accept