Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Find my JSON file below.

{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-WebApplication7-0de8c0d7-92a5-43b4-a3f1-afeed2785dfe",
"version": "1.0.0-*",

"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5",
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
},

"exclude": [
"wwwroot",
"node_modules",
"bower_components"
}

I can read value of "webroot" as string and "exclude" as array using following snippet.

C#
string file = File.ReadAllText("project.json");
Product pro = JsonConvert.DeserializeObject<Product>(file);



My requirement is to read each value under dependency node and validate it. Then to add a new value and write it back to the json fie. Please help.
Posted
Comments
F-ES Sitecore 14-Oct-15 4:50am    
Rather than using a concrete Product class you might need to use dynamic objects

http://stackoverflow.com/questions/8738031/deserializing-json-using-json-net-with-dynamic-data

https://weblog.west-wind.com/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing

or use newtonsoft's native jobject type classes. Google for "dynamic json newtonsoft" and you'll find other examples.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900