using System; using System.IO; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace analyzeJSON { public class AnalyzeJSON { private readonly JObject json; public AnalyzeJSON(string path) { if (!File.Exists(path)) throw new ArgumentNullException("File doesn't exist!"); using StreamReader sr = new StreamReader(path); var jsonString = sr.ReadToEnd(); json = JsonConvert.DeserializeObject(jsonString); } public static string GetNameFromPath(string tokenPath) { return tokenPath.Split(".").Last(); } private void Traverse(IJEnumerable tokens, Action action) { foreach (var token in tokens) { action.Invoke(token); if (token.HasValues) Traverse(token.Children(), action); } } public void Traverse(Action action) { if (!json.HasValues) return; Traverse(json.Children(), action); } } }