title: How to read from a file and put the contents into a json method in Python?
body: <p>I am trying to read the data from a file that has content that looks like this</p>
  
  <pre><code>{"name": "Host1","type": "ipmask","subnet": ["0.0.0.0","255.255.255.255"],"dynamic_mapping": None},
  {"name": "Host2","type": "ipmask","subnet": ["0.0.0.0","255.255.255.255"],"dynamic_mapping": None},
  </code></pre>
  
  <p>into a variable in python so that I can use it in the code below for a post request using JSON. </p>
  
  <pre><code>with open('data.txt', 'r') as file:
      dat2 = file.read()
  
  post2 = {
          "id": 5,
          "method": "set",
          "params": [
              {
                  "data": [
                       dat2
                      ],
                  "url": "/config/url"
              },
          "session": sessionkey,
          "verbose": 1
          }
  </code></pre>
  
  <p>I'm stuck because when I copy and past the data into the JSON where dat2 is, the request goes through sucessfully. I really don't understand what I am doing wrong, I have even tried stripping newlines and whitepaces. If anyone could help I would greatly appreciate it.</p>