0

I am getting a Json Array here is the JSON array

[
  {
    "customFieldName": "resolution",
    "fieldName": "Resolution"
  },

  {
    "customFieldName": "lastViewed",
    "fieldName": "Last Viewed"
  },
]

I want to convert the Keys to lower case please suggest the solution. I tried to convert the JSON array to dictionary but not succeeded.

2

1 Answer 1

1

You can try reading all properties inside JsonArray and change the propertyname to lowercase

private static void ConvertToLowerCase(JArray jArray)
{
    foreach (var item in jArray.Children())
    {
        foreach (var property in item.Children<JProperty>().ToList())
        {
            property.Replace(new JProperty(property.Name.ToLower(), property.Value));
        }
    }
}

call this method by passing the JArray

var jArray = JArray.Parse(jsonString);
ConvertToLowerCase(jArray);
Console.WriteLine(JsonConvert.SerializeObject(jArray));

Output

[{"customfieldname":"resolution","fieldname":"Resolution"},{"customfieldname":"lastViewed","fieldname":"Last Viewed"}]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.