I'm trying to add a property to a json object, which are not root of the json.
example is below.
{
'isFile' : 'true',
'Values' : {
'valueName1': 'value1',
'valueName2': 'value2',
'valueName3': 'value3',
}
}
after the operation, i want the json file to look like below.
{
'isFile' : 'true',
'Values' : {
'valueName1': 'value1',
'valueName2': 'value2',
'valueName3': 'value3',
'valueName4': 'value4'
}
}
I have gotten to the point where I can access Values property through below code. Where do I go next?
JObject appSettings = JsonConvert.DeserializeObject<JObject>(jsonString);
string values = appSettings["Values"].ToString();
any help?
*Edit I'm trying to edit values section for local.settings.json file for azure app function in Visual Studio.
you can do it with a dynamic object
dynamic obj = JsonConvert.DeserializeObject<ExpandoObject>(jsonString);
obj.Values.valueName4 = "value4";
System.Console.WriteLine(JsonConvert.SerializeObject(obj));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With