title: python and Json - editing file
body: <p>So, I want to change my info in json file from python, but I am having trouble.
  my json file is just info that I want to edit later:</p>
  <pre><code>[
    {
      &quot;codigo&quot;: 10,
      &quot;Nom_articulo&quot;: &quot;jabon&quot;,
      &quot;valor&quot;: 2500,
      &quot;cantidad&quot;: 6,
      &quot;subtotal&quot;: 0,
      &quot;descuento&quot;: 0
    },
    {
      &quot;codigo&quot;: 20,
      &quot;Nom_articulo&quot;: &quot;Crema&quot;,
      &quot;valor&quot;: 9800,
      &quot;cantidad&quot;: 4,
      &quot;subtotal&quot;: 0,
      &quot;descuento&quot;: 0
    },
    {
      &quot;codigo&quot;: 30,
      &quot;Nom_articulo&quot;: &quot;Cepillo&quot;,
      &quot;valor&quot;: 6000,
      &quot;cantidad&quot;: 7,
      &quot;subtotal&quot;: 0,
      &quot;descuento&quot;: 0
    },
    {
      &quot;codigo&quot;: 40,
      &quot;Nom_articulo&quot;: &quot;Servilletas&quot;,
      &quot;valor&quot;: 3000,
      &quot;cantidad&quot;: 2,
      &quot;subtotal&quot;: 0,
      &quot;descuento&quot;: 0
    },
    {
      &quot;codigo&quot;: 50,
      &quot;Nom_articulo&quot;: &quot;Desodorante&quot;,
      &quot;valor&quot;: 5000,
      &quot;cantidad&quot;: 6,
      &quot;subtotal&quot;: 0,
      &quot;descuento&quot;: 0
    }
  ]
  </code></pre>
  <p>I want to change the value of &quot;subtotal&quot; in all my dictionaries.</p>
  <p>so basically what I did was:</p>
  <pre><code>for i in range(len(archivo_r)):
                  precio= archivo_r[i][&quot;valor&quot;]
                  cantidad=archivo_r[i][&quot;cantidad&quot;]
                  subtotal=precio*cantidad
                  print(archivo_r[i][&quot;codigo&quot;], &quot; - &quot; ,archivo_r[i][&quot;Nom_articulo&quot;], &quot; = &quot;, str(subtotal))
                  #almacenar mis subtotales en el archivo json
                  print(&quot;sbtotal&quot; ,archivo_r[i][&quot;subtotal&quot;])
                  archivo_r[i][&quot;subtotal&quot;]=subtotal
                  #archivo_r[i][&quot;subtotal&quot;].append(subtotal)
                  #print(archivo_r)
              write_json(**XXXXX**)
  </code></pre>
  <p>This part of the code:
  <code>archivo_r[i][&quot;subtotal&quot;]=subtotal</code> does exactly what I need, but (and this could be very silly, but I am a little lost here) I do not know how to use that to re-write my json file. I mean, I have the function to write it.</p>
  <pre><code>def write_json(info, nombre_archivo=&quot;productos.json&quot;):
      with open(nombre_archivo, &quot;w&quot;) as p:
          json.dump(info, p)
  </code></pre>
  <p>I need to pass the information in  <code>write_json(**XXXXX**)</code>, but have been trying to storage my <code>archivo_r[i][&quot;subtotal&quot;]=subtotal</code> in a variable to pass it and other things, but nothing work. I know I am doing wrong but not sure how to solve it.</p>