title: How to convert json to Dictionary
body: <p>I have to convert the JSON string to Dictionary&lt; string, object >. For that, I am following something here <a href="https://www.programming-books.io/essential/csharp/collect-all-fields-of-json-object-5293c4c9342c403bb40dd9232692a7bc" rel="nofollow noreferrer">https://www.programming-books.io/essential/csharp/collect-all-fields-of-json-object-5293c4c9342c403bb40dd9232692a7bc</a> and doing DotNotation to convert it to Dictionary however, the output is not as expected.</p>
  
  <p>JSON Data I am trying:</p>
  
  <pre><code>{
    "name": "Madame Uppercut",
    "age": 39,
    "secretIdentity": "Jane Wilson",
    "powers": [
      "Million tonne punch",
      "Damage resistance",
      "Superhuman reflexes"
    ],
    "accounting": [
      {
        "firstName": "John",
        "lastName": "Doe",
        "age": 23
      },
      {
        "firstName": "Mary",
        "lastName": "Smith",
        "age": 32
      }
    ]
  }
  </code></pre>
  
  <p>Using the code from above link and converting from DotNotation as below</p>
  
  <pre><code> var dictionary = new Dictionary&lt;string, object&gt;();
              foreach (var jsonInput in dotNotation)
              {
                  var hierarchy = jsonInput.Key.Split('.');
  
                  var bottom = dictionary;
  
                  for (int i = 0; i &lt; hierarchy.Length; i++)
                  {
                      var key = hierarchy[i];
  
                      if (i == hierarchy.Length - 1)
                      {
                          bottom.Add(key, jsonInput.Value);
                      }
                      else
                      {
                          if (!bottom.ContainsKey(key))
                              bottom.Add(key, new Dictionary&lt;string, object&gt;());
  
                          bottom = (Dictionary&lt;string, object&gt;)bottom[key];
                      }
                  }
              }
  </code></pre>
  
  <p>finally, the result is like.</p>
  
  <p><a href="https://i.stack.imgur.com/B534X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B534X.png" alt="enter image description here"></a></p>
  
  <p>Now, what I want is to group the arrays(powers and accounting). I know the JToken path is giving '[]' array path but I want it like below for power and account in the dictionary.</p>
  
  <pre><code>{[power, [{"Million tonne punch" }, {"Damage resistance" }, {"Superhuman reflexes"}]]}
  </code></pre>