I have a json structure like this:
json["report"] = new JObject
{
{ "name", fm.Name }
};
Newtonsoft is using more direct-like approach, where You can access any property via square brackets []
. You just need to set the JObject
, which have to be created based on Newtonsoft specifics.
Full code:
var json = JObject.Parse(@"
{
""report"": {},
""expense"": {},
""invoices"": {},
""settings"": {
""users"" : {}
},
}");
Console.WriteLine(json.ToString());
json["report"] = new JObject
{
{ "name", fm.Name }
};
Console.WriteLine(json.ToString());
Output:
{
"report": {},
"expense": {},
"invoices": {},
"settings": {
"users": {}
}
}
{
"report": {
"name": "SomeValue"
},
"expense": {},
"invoices": {},
"settings": {
"users": {}
}
}
As a reference, You can look at this link: https://www.newtonsoft.com/json/help/html/ModifyJson.htm