© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
10 replies
VoidPointer

✅ How to specify camel case for all response properties with Newtonsoft

This is the type of JSON I receive from an external API:
    "phoneValidation": {
      "success": true,
      "data": {
        "number": "27101238765",
        "valid": true,
        "account_details": {
          "google": {
            "registered": false,
            "full_name": null
          },
          "twitter": {
            "registered": true
          },
          "skype": {
            "registered": false,
            "age": null,
            "city": null,
          },
          "whatsapp": {
            "registered": true,
            "last_active": null
          },
          "telegram": {
            "registered": null,
            "photo": null,
          },
    "phoneValidation": {
      "success": true,
      "data": {
        "number": "27101238765",
        "valid": true,
        "account_details": {
          "google": {
            "registered": false,
            "full_name": null
          },
          "twitter": {
            "registered": true
          },
          "skype": {
            "registered": false,
            "age": null,
            "city": null,
          },
          "whatsapp": {
            "registered": true,
            "last_active": null
          },
          "telegram": {
            "registered": null,
            "photo": null,
          },

This I deserialize into this DTO:
public class ValidatePhoneNumberReceived
{
    public bool Success { get; set; }
    public ValidatePhoneNumberData Data { get; set; }

    public class ValidatePhoneNumberData
    {
        public string Number { get; set; }
        public Dictionary<string, object> AccountDetails { get; set; }
    }
}
public class ValidatePhoneNumberReceived
{
    public bool Success { get; set; }
    public ValidatePhoneNumberData Data { get; set; }

    public class ValidatePhoneNumberData
    {
        public string Number { get; set; }
        public Dictionary<string, object> AccountDetails { get; set; }
    }
}

Then I do some stuff, and return the same model from my own API.

AccountDetails
AccountDetails
contains
object
object
, because for each key, the external API returns a different set of properties, as we see in the json
account_details.google
account_details.google
, and
account_details.whatsapp
account_details.whatsapp
etc.

They appear in my response with the same snake case I received them with. I have even tried adding an action filter to add a
NewtonsoftJsonOutputFormatter
NewtonsoftJsonOutputFormatter
set to camel case.

How can I force the dynamic properties to be camel case?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Newtonsoft, count nested properties
C#CC# / help
4y ago
✅ How to convert controller route name to camel case automatically?
C#CC# / help
11mo ago
✅ Serialized enum starts with uppercase / camel case is ignored
C#CC# / help
13mo ago
How can I make FluentValidation return errors in camel case??
C#CC# / help
15mo ago