0

I have this code to generate the output shown below, when I debug the code, I can see the "CostLine.ExternalId" but when the result is shown in Postman, the case has changed to "costLine.ExternalId", Is there any way that we could prevent this?

Code:

rows[row.Id] = new Dictionary<string, List<string>> {
   {
      "CostLine.ExternalId", ["123456", "7959587", "8752296"]
   }
};

Result:

"rows": {
            "9335b339-d283-4175-bb4d-53f133fdee46": {
                "costLine.ExternalId": [
                    "123456"
                ]
            },
            "c557f6cc-b443-41ac-9214-601b3cb24326": {
                "costLine.ExternalId": [
                    "7959587", "8752296"
                ]
            }
        }

I have tried StringComparer.InvariantCultureIgnoreCase but does not work. Any help is highly appreciated.

2
  • 4
    You didn't share some key information. We see a dictionary initialization, and then a fragment of a JSON document. Between the two there must be some serializer that is "smart" enough to apply some casing rule to the JSON object property names. Commented Jul 31, 2024 at 10:32
  • You are right, there is a code in Startup.cs which applies camel case for the controller outputs. I will see if I can override this setting. Thank you Commented Jul 31, 2024 at 10:45

1 Answer 1

1

Newtonsoft's JSON "NamingStrategy" property is "taking care" of camel-casing or not the object property names. Please see the following example: Configure NamingStrategy property name serialization

With Microsoft JSON configuration it's a little bit different: How to customize property names and values with System.Text.Json

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.