title: how to convert txt file into json using python?
body: <p>I'm writing a log file using python and the log file is like this :</p>
  
  <pre><code>MessageName:mouse left down | TimeStamp:2019-02-13 15:43:31.664 |  Window:13500784 | Position:(483, 587) | Wheel:0
  MessageName:mouse left up | TimeStamp:2019-02-13 15:43:31.873 | Window:13500784 | Position:(483, 587) | Wheel:0
  </code></pre>
  
  <p>I would like to convert this log into json format.</p>
  
  <p>This is the code that i have tried : </p>
  
  <pre><code>import json
  
  def convert() :
  f = open("log_events.log", "r")
  content = f.read()
  splitcontent = content.splitlines()
  
  for line in splitcontent :
      pipesplit = line.split(' | ')
      print(pipesplit)
      with open("json_log.json", 'a') as fout:
          json.dump(pipesplit, fout, indent=4)
  </code></pre>
  
  <p>And the Output i need is like this  : </p>
  
  <pre><code>[
  {
      "MessageName" : "mouse left down",
      "TimeStamp" : "2019-02-13 15:43:31.664",
      "Window" : "13500784",
      "Position" : "(483, 587)",
      "Wheel" : 0"
  },
  {
      "MessageName" : "mouse left up",
      "TimeStamp" : "2019-02-13 15:43:31.873",
      "Window" : "13500784",
      "Position" : "(483, 587)",
      "Wheel" : "0"
  },
  
  ]
  </code></pre>
  
  <p>But with the above given code, my output is </p>
  
  <pre><code>[
      "MessageName" : "mouse left down",
      "TimeStamp" : "2019-02-13 15:43:31.664",
      "Window" : "13500784",
      "Position" : "(483, 587)",
      "Wheel" : 0"
  ][
      "MessageName" : "mouse left up",
      "TimeStamp" : "2019-02-13 15:43:31.873",
      "Window" : "13500784",
      "Position" : "(483, 587)",
      "Wheel" : "0"
  ]
  </code></pre>
  
  <p>How to convert into proper JSON format ?</p>