title: Get nested dictionary from ImmutableMultiDict without iteration
body: <p><strong>title seems like a common problem but before marking as duplicate post please read at first</strong></p>
  <p>I am passing a <code>javaScript object</code> via <code>POST</code> method to <code>Flask</code>. But I think it converts to <code>JSON</code> format(due to insufficient knowledge I am not confident about this statement). On the client-side, I have printed the value of the JavaScript object and got</p>
  <pre><code>{
    &quot;0001_Summer&quot;: {
      &quot;value&quot;: [
        &quot;value_05&quot;,
        &quot;value_02&quot;,
        &quot;value_03&quot;
      ]
    },
    &quot;0003_Spring&quot;: {
      &quot;value&quot;: [
        &quot;All&quot;,
        &quot;value_04&quot;,
        &quot;value_03&quot;
      ]
    },
    &quot;0002_Winter&quot;: {
      &quot;value&quot;: [
        &quot;value_04&quot;,
        &quot;value_07&quot;,
        &quot;value_02&quot;
      ]
    },
    &quot;Query&quot;: &quot;56&quot;
  }
  </code></pre>
  <p>The way of submission from JavaScript is as like as follows in my case</p>
  <pre><code>function POST_Query_data() {
      hiddenform = document.createElement(&quot;form&quot;)
      hiddenform.style.visibility = &quot;hidden&quot;;
      hiddenform.method = &quot;POST&quot;;
      // json_for_backend this is the final json in my case
  
      for ([key, value] of Object.entries(json_for_backend)) {
          i_1 = document.createElement(&quot;input&quot;);
          i_1.name = key;
          i_1.value = JSON.stringify(value);
          hiddenform.appendChild(i_1);
      }
      document.getElementById(&quot;body&quot;).appendChild(hiddenform);
      hiddenform.submit();
  }
  
  </code></pre>
  <p>While I click on <code>submit</code> then <code>POST_Query_data</code> is triggered.</p>
  <p>After passing this object via <code>POST</code> method in Flask I have printed <code>request.form</code> and got</p>
  <pre><code>ImmutableMultiDict([('0001_Summer', '{&quot;value&quot;:[&quot;value_05&quot;,&quot;value_02&quot;,&quot;value_03&quot;]}'), ('0003_Spring', '{&quot;value&quot;:[&quot;All&quot;,&quot;value_04&quot;,&quot;value_03&quot;]}'), ('0002_Winter', '{&quot;value&quot;:[&quot;value_04&quot;,&quot;value_07&quot;,&quot;value_02&quot;]}'), ('Query', '&quot;56&quot;')])
  </code></pre>
  <p>By following the <a href="https://tedboy.github.io/flask/generated/generated/werkzeug.ImmutableMultiDict.to_dict.html" rel="nofollow noreferrer">documentation</a> I have converted this <code>ImmutableMultiDict</code> to a regular <code>dict</code> type</p>
  <pre><code>from flask import Flask, render_template, request
  @app.route('/', methods=['POST', 'GET'])
  def foo(name=None):
      if request.method == 'POST':
          converted_dict = {}
          converted_dict = request.form.to_dict()
  
      return render_template('index.html',name=name)
  </code></pre>
  <p>After printing <code>converted_dict</code> I have found</p>
  <pre><code>{'0001_Summer': '{&quot;value&quot;:[&quot;value_05&quot;,&quot;value_02&quot;,&quot;value_03&quot;]}', '0003_Spring': '{&quot;value&quot;:[&quot;All&quot;,&quot;value_04&quot;,&quot;value_03&quot;]}', '0002_Winter': '{&quot;value&quot;:[&quot;value_04&quot;,&quot;value_07&quot;,&quot;value_02&quot;]}', 'Query': '&quot;56&quot;'}
  </code></pre>
  <p>where it is seen that the value of each key(<code>eg: 0001_Summer</code>) is a string while I need them also in a <code>dict</code> type. I have found tons of post regarding conversion of <code>string to dict</code> and followed <a href="https://stackoverflow.com/questions/988228/convert-a-string-representation-of-a-dictionary-to-a-dictionary">one</a>.</p>
  <pre><code>import ast
  for a in converted_dict:
      for key, val in ast.literal_eval(converted_dict[a]).items():
          # done processing with &quot;val&quot;(dict type from string) 
  </code></pre>
  <p>But I am looking for any faster way to convert from <code>ImmutableMultiDict</code> to a <code>nested dict</code> form as in the above process I have to iterate using a <code>for loop</code> which I believe for a large data will cause a overhead.</p>