title: How to recursively populate a TreeView with JSON data
body: <p>I have a winforms treeview, I can read data automatically, (a node that is equal to key, and a node inside that is equal to value), but when reading object type, the values inside it are not going to be child of object node (key of object), (maybe I couldnt explain well, here is a screenshot and my methods.)</p>
  
  <p>layer0 needs to be inside textures and scale needs to be inside display</p>
  
  <p><a href="https://i.stack.imgur.com/Qf3Ya.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Qf3Ya.png" alt="layer0 needs to be inside textures and scale needs to be inside display"></a></p>
  
  <p>My Json:    </p>
  
  <pre><code>{
  "parent": "builtin/generated",
  "textures": {
      "layer0": "mm:items/iron_dust"
  },
  "display": {       
          "scale": [ 1.7, 1.7, 1.7 ]
   }
  }
  </code></pre>
  
  <p>My method to auto detect(not all mine actually)</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
      {
          StreamReader reader = new StreamReader(path);
          string json = reader.ReadToEnd();
          reader.Close();
          JObject obj = JObject.Parse(json);
          getAllProperties(obj);
      }
  
      void getAllProperties(JToken children)
      {
          TreeNode mainNode = treeView1.Nodes[0];
          mainNode.Text = Path.GetFileNameWithoutExtension(path);
          foreach (JToken child in children.Children())
          {
              var property = child as JProperty;
              if (property != null)
              {
                  if (property.Value.Type == JTokenType.String)
                  {
                      TreeNode keyNode = mainNode.Nodes.Add(property.Name);
                      keyNode.Nodes.Add(property.Value.ToString());
                  }
                  if (property.Value.Type == JTokenType.Array)
                  {
                      JArray array = (JArray)property.Value;
                      TreeNode node = mainNode.Nodes.Add(property.Name);
                      for (int i = 0; i &lt; array.Count; i++)
                      {
                          node.Nodes.Add(array[i].ToString());
                      }
                  }
                  if (property.Value.Type == JTokenType.Object)
                  {
                      TreeNode topNode = mainNode.Nodes.Add(property.Name.ToString());
                      foreach (var item in property)
                      {
                          if (item.Type == JTokenType.String)
                          {
                               if (property.Value.Type == JTokenType.String)
                  {
                      TreeNode keyNode = topNode.Nodes.Add(property.Name);
                      keyNode.Nodes.Add(property.Value.ToString());
                  }
                  if (property.Value.Type == JTokenType.Array)
                  {
                      JArray array = (JArray)property.Value;
                      TreeNode node = topNode.Nodes.Add(property.Name);
                      for (int i = 0; i &lt; array.Count; i++)
                      {
                          node.Nodes.Add(array[i].ToString());
                      }
                  }
                          }
                      }
                  }
  
  
                      // Console.WriteLine(property.Name + ":" + property.Value);//print all of the values
                  }
                  getAllProperties(child);
              }
          }
  
      }
  </code></pre>
  
  <p>I tried to get parent, but it didnt have name and value properties :S.
  Any help?
  (Sorry for language mistakes)</p>