How to update a property of a JSON object using NewtonSoft

You can access the object by using properties as keys:

JObject obj = JObject.Parse(json);
string gender = (string)obj["value"]["option"];

For your example, try:

JObject obj = JObject.Parse(json);
var val = obj["value"];
string option = (string)val["option"];

if (option == "ML")
   val["option"] = "Male";

if (option == "FM")
   val["option"] = "Female";

string result = obj.ToString();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)