title: Modify json attribute with Python but getting FileNotFoundError: [Errno 2] No such file or directory
body: <p>I have 25 json files in a folder, named 0.json through 24.json, and I am trying to batch open and rename a perimeter &quot;image&quot; inside of each, which currently all have a placeholder of &quot;https://&quot; in the &quot;image&quot; field.</p>
  <p>I have a central folder on a site like dropbox, that has a url structure of https://weburlofnewimage/0, /1, /2 etc.  And so I would like to open each file, and change the value of the &quot;image&quot; key to be replaced with &quot;https://weburlofnewimage/ + current file number + '.png'&quot;.</p>
  <p>The .json currently appears as follows for each json file:</p>
  <pre><code>
  {&quot;image&quot;: &quot;https://&quot;, &quot;attributes&quot;: [{&quot;trait_type&quot;: &quot;box color&quot;, &quot;value&quot;: &quot;blue&quot;}, {&quot;trait_type&quot;: &quot;box shape&quot;, &quot;value&quot;: &quot;square&quot;}]}
  
  </code></pre>
  <p>but should be</p>
  <pre><code>{&quot;image&quot;: &quot;https://weburlofnewimage/0&quot;, &quot;attributes&quot;: [{&quot;trait_type&quot;: &quot;box color&quot;, &quot;value&quot;: &quot;blue&quot;}, {&quot;trait_type&quot;: &quot;box shape&quot;, &quot;value&quot;: &quot;square&quot;}]}
  </code></pre>
  <p>So far I have tried the following, but I believe I am going down a rabbit hole</p>
  <pre><code>import json
  import os
  
  folderPath = r'/path/FolderWithJson'
  fileNumber = 0
  
  for filename in os.listdir(folderPath):
      with open(filename, 'r') as f:
          data = json.load(f)
          data['id'] = str('https://weburlofnewimage/' + str(fileNumber) + '.png')
      os.remove(filename)
      with open(filename, 'w') as f:
          json.dump(data, f, indent=4)
  
      fileNumber +=1
  </code></pre>
  <p>and have tried:</p>
  <pre><code>import os
  import json
  
  folderPath = r'/path/FolderWithJson'
  fileNumber = 0
  
  for filename in os.listdir(folderPath):
      with open(filename, 'r+') as f:
          data = json.load(f)
          data['image'] = str('https://weburlofnewimage/' + str(fileNumber)
          f.seek(0)
          json.dump(data, f, indent=4)
          f.truncate()     # remove remaining part
          fileNumber +=1
  
          
  </code></pre>
  <p>However, in both cases I get the following error:</p>
  <pre><code>FileNotFoundError: [Errno 2] No such file or directory: '20.json'
  </code></pre>
  <p>However, the file is indeed in that directory...</p>