title: How to convert post to Json - Django
body: <p>I'm trying to convert data from a post to Json formed.</p>
  <p>But I still haven't had success.</p>
  <p>I tried to do in this format</p>
  <p>Unfortunately I couldn't think of anything.</p>
  <p>Could anyone help?</p>
  <p>Post</p>
  <pre><code>{'csrfmiddlewaretoken': 'AdbaFrsoWeZTnT07m3VjncmYnYHztaQ214qh8AYH2cI40veXfe0dmfSwkI1o2ma1',
   'det[0][CNPJ]': '8768678678678',
   'det[0][UF]': 'SP',
   'det[0][dhEmi]': '2021-07-13T08:26:30-03:00',
   'det[0][nNF]': '8267',
   'det[0][xNome]': 'INDÚSTRIA',
   'prod[0][0][CFOP]': '6102',
   'prod[0][0][NCM]': '84384000',
   'prod[0][0][UF]': 'SP',
   'prod[0][0][aliquotaInterna]': '18',
   'prod[0][0][counter]': '1',
   'prod[0][0][mva]': '34',
   'prod[0][0][tributacaoEstadual]': '7',
   'prod[0][0][vICMSST]': '0',
   'prod[0][0][vICMS]': '25.74',
   'prod[0][0][vIPI]': '0',
   'prod[0][0][vProd]': '367.68',
   'prod[0][0][xProd]': 'FUSO',
   'prod[0][1][CFOP]': '6102',
   'prod[0][1][NCM]': '84384000',
   'prod[0][1][UF]': 'SP',
   'prod[0][1][aliquotaInterna]': '18',
   'prod[0][1][counter]': '2',
   'prod[0][1][mva]': '23',
   'prod[0][1][tributacaoEstadual]': '7',
   'prod[0][1][vICMSST]': '0',
   'prod[0][1][vICMS]': '15.96',
   'prod[0][1][vIPI]': '0',
   'prod[0][1][vProd]': '228.07',
   'prod[0][1][xProd]': 'PORCA',
   'xNome': 'COMERCIAL'}
  </code></pre>
  <hr />
  <p>View</p>
  <pre><code>if post:
              import re
              pattDet = re.compile('^([a-zA-Z_]\w+.)\[([0-9_\-][\w\-]*)\]\[([a-zA-Z_\-][\w\-]*)\]$')
              pattProd = re.compile('^([a-zA-Z_]\w+.)\[([0-9_\-][\w\-]*)\]\[([0-9_\-][\w\-]*)\]\[([a-zA-Z_\-][\w\-]*)\]$')
              pprint.pprint(post)
  
              det = []
              prodtem = []
              count = 0
              for post_name, value in post.items():
                  try:
                      det_count = int(pattDet.match(post_name).group(2))
                      if pattDet.match(post_name).group(1) == 'det':
                          det[pattDet.match(post_name).group(3)] = value
                  except:
                      pass
  
                  try:
  
                      if pattProd.match(post_name).group(1) == 'prod':
  
                          if count == int(pattProd.match(post_name).group(3)):
  
                              prodtem.insert(count, {pattProd.match(post_name).group(4): value})
  
                          else:
                              count += 1
  
                  except Exception as e:
                      print(e)
                      pass
  
              result.append({
                  'det': det,
                  'prod': prodtem
              })
  </code></pre>