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.

Gaurav_0093
  • 1,040
  • 6
  • 28
  • 56

1 Answers1

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"}]
Krishna Varma
  • 4,238
  • 2
  • 10
  • 25