title: Python: Best way to convert file with key=value lines into json
body: <p>I have a data file with lines containing key=value. I want to read this file from python and convert it to a json object such as <code>{"key"="value"}</code>.</p>
  
  <p>datafile:</p>
  
  <pre><code>a=b
  c=d 
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>{
    "a": "b",
    "c": "d"
  }
  </code></pre>
  
  <p>I have successfully done this with the following code:</p>
  
  <pre><code>j = {}
  with open('datafile') as f:
      lines = f.readlines()
      for line in lines:
          s=line.strip().split('=')
          j[s[0]]=s[1]
  </code></pre>
  
  <p>However, being new with Python and realizing there is usually a super short beautiful solution to most problems like this, I am wondering if there is indeed a much prettier one-line-ish solution to this problem? </p>