title: How can I convert a hierarchy dictionary into a format identifying text and nodes?
body: <p>I am new to python and I was looking for a way to convert the following dictionary into a format that is outlined below it using some code.</p>
  <pre><code>{'Parent 1': {'Child 1': {Grandchild 1: {}, 'Grandchild 2: {}}, 'Child 2': {}} Parent 2: {}}
  </code></pre>
  <p>And then convert this to:</p>
  <pre><code>{
      'text': &quot;Parent 1&quot;,
      'nodes': [
          {
              'text': &quot;Child 1&quot;,
              'nodes': [
                  {
                      'text': &quot;Grandchild 1&quot;
                  },
                  {
                      'text': &quot;Grandchild 2&quot;
                  }
              ]
          },
          {
              'text': &quot;Child 2&quot;
          }
      ]
  },
  {
      'text': &quot;Parent 2&quot;
  }
  </code></pre>