title: Python - Deleting Lines of Code In JSON File
body: <p>I would like to search and replace multiple lines of code a JSON file with nothing except the first one that will use the users input but I cant get it to work I would like to search a JSON file and find the code im looking for and remove it or replace it with nothing.</p>
  
  <p>I want to delete everything like the stuff inside and the { and the closing }, tag in my JSON file.</p>
  
  <p>Code:</p>
  
  <pre><code>screenshoturl = input("Screenshot URL 1: ")
  
  # Search JSON file for the placeholders and replace them with nothing.
  removescreenshotsplaceholders = {
    'Screenshot URL 1':screenshoturl,
    '''{
    "accessibilityText": "Screenshot",
    "url": "Screenshot URL 2",
    "fullSizeURL": "Screenshot URL 2"
    },''':'',
    '''{
    "accessibilityText": "Screenshot",
    "url": "Screenshot URL 3",
    "fullSizeURL": "Screenshot URL 3"
    },''':'',
    '''{
    "accessibilityText": "Screenshot",
    "url": "Screenshot URL 4",
    "fullSizeURL": "Screenshot URL 4"
    },''':'',
    '''{
    "accessibilityText": "Screenshot",
    "url": "Screenshot URL 5",
    "fullSizeURL": "Screenshot URL 5"
    }''':''
    }
  
    with open('path/to/json/file') as infile, open(/path/to/to/save/copy, 'w') as outfile:
        for removescreenshots in infile:
            for screenshot, removescreenshot in removescreenshotsplaceholders.items():
                removescreenshots = removescreenshots.replace(screenshot, removescreenshot)
            outfile.write(removescreenshots)
  </code></pre>
  
  <p>This is what I want the script to search for in the JSON file and remove it:</p>
  
  <pre><code>'''{
        "accessibilityText": "Screenshot",
        "url": "Screenshot URL 2",
        "fullSizeURL": "Screenshot URL 2"
        },''':'',
        '''{
        "accessibilityText": "Screenshot",
        "url": "Screenshot URL 3",
        "fullSizeURL": "Screenshot URL 3"
        },''':'',
        '''{
        "accessibilityText": "Screenshot",
        "url": "Screenshot URL 4",
        "fullSizeURL": "Screenshot URL 4"
        },''':'',
        '''{
        "accessibilityText": "Screenshot",
        "url": "Screenshot URL 5",
        "fullSizeURL": "Screenshot URL 5"
        }''':''
  </code></pre>
  
  <p>JSON file:</p>
  
  <pre><code>{
    "tabs": [
      {
        "tabname": "Details",
        "views": [
          {
            "title": "Some Name",
            "useBoldText": true,
            "useBottomMargin": false,
            "class": "DepictionSubheaderView"
          },
          {
            "itemCornerRadius": 6,
            "itemSize": "",
            "screenshots": [
              {
                "accessibilityText": "Screenshot",
                "url": "Screenshot URL 1",
                "fullSizeURL": "Screenshot URL 1"
              },
              {
                "accessibilityText": "Screenshot",
                "url": "Screenshot URL 2",
                "fullSizeURL": "Screenshot URL 2"
              },
              {
                "accessibilityText": "Screenshot",
                "url": "Screenshot URL 3",
                "fullSizeURL": "Screenshot URL 3"
              },
              {
                "accessibilityText": "Screenshot",
                "url": "Screenshot URL 4",
                "fullSizeURL": "Screenshot URL 4"
              },
              {
                "accessibilityText": "Screenshot",
                "url": "Screenshot URL 5",
                "fullSizeURL": "Screenshot URL 5"
              }
            ],
            "ipad": {
              "itemCornerRadius": 9,
              "itemSize": "{320, 550.8266666666667}",
              "screenshots": [
                {
                  "accessibilityText": "Screenshot",
                  "url": " Screenshot URL?size=640",
                  "fullSizeURL": "Screenshot URL"
                }
              ],
              "class": "DepictionScreenshotView"
            },
            "class": "DepictionScreenshotsView"
          },
          {
            "markdown": " Description",
            "useSpacing": true,
            "class": "DepictionMarkdownView"
          },
          {
            "class": "DepictionSeparatorView"
          },
          {
            "title": "Known Issues",
            "class": "DepictionHeaderView"
          },
          {
            "markdown": "None",
            "useSpacing": true,
            "class": "DepictionMarkdownView"
          },
          {
            "class": "DepictionSeparatorView"
          },
          {
            "title": "Latest Version",
            "class": "DepictionHeaderView"
          },
          {
            "title": "1.0",
            "text": "Latest Version Number",
            "class": "DepictionTableTextView"
          },
          {
            "title": "Released",
            "text": "3/10/19",
            "class": "DepictionTableTextView"
          },
          {
            "title": "Price",
            "text": "Free",
            "class": "DepictionTableTextView"
          },
          {
            "title": "Developer",
            "text": "TestDev",
            "class": "DepictionTableTextView"
          },
          {
            "title": "Contact Support",
            "action": "",
            "class": "DepictionTableButtonView"
          },
          {
            "spacing": 16,
            "class": "DepictionSpacerView"
          },
          {
            "spacing": 20,
            "class": "DepictionSpacerView"
          }
        ],
        "class": "DepictionStackView"
      },
      {
        "tabname": "Changelog",
        "views": [
          {
            "title": "1.0",
            "useBoldText": true,
            "useBottomMargin": true,
            "class": "DepictionSubheaderView"
          },
          {
            "markdown": "\t\n\u2022 Initial Release",
            "useSpacing": false,
            "class": "DepictionMarkdownView"
          },
          {
            "markdown": "&lt;small style=\"color: #999; margin-top: -8px;\"&gt;Released 3/10/2019&lt;/small&gt;",
            "useRawFormat": true,
            "class": "DepictionMarkdownView"
          }
        ],
        "class": "DepictionStackView"
      }
    ],
    "class": "DepictionTabView"
  }
  </code></pre>
  
  <p>I tried it with and without <code>'''</code> and tried messing with the in and out file and some other stuff nothing seems to work so any help will be welcomed.</p>
  
  <p>Thanks!</p>