title: How to convert the extracted text from PDF to JSON or XML format in Python?
body: <p>I am using PyPDF2 to extract the data from PDF file and then converting into Text format? </p>
  
  <p>PDF format for the file is like this: </p>
  
  <pre><code>Name : John 
  Address: 123street , USA 
  Phone No:  123456
  Gender: Male 
  
  Name : Jim 
  Address:  456street , USA 
  Phone No:  456899
  Gender: Male 
  </code></pre>
  
  <p>In Python I am using this code: </p>
  
  <pre><code>import PyPDF2
  pdf_file = open('C:\\Users\\Desktop\\Sampletest.pdf', 'rb')
  read_pdf = PyPDF2.PdfFileReader(pdf_file)
  number_of_pages = read_pdf.getNumPages()
  page = read_pdf.getPage(0)
  page_content = page.extractText()
  page_content
  </code></pre>
  
  <p>This is the outcome which I get from page_content:</p>
  
  <pre><code> 'Name : John \n \nAddress: 123street , USA \n \nPhone No:  123456\n \nGender: Male \n \n \nName : Jim \n \nAddress:  456street , USA \n \nPhone No:  456899\n \nGender: Male \n \n \n'
  </code></pre>
  
  <p>How do I format it in a JSON or XML format so that I could use extracted data in SQL server database. </p>
  
  <p>I tried using this approach as well </p>
  
  <pre><code>import json
  data = json.dumps(page_content)
  formatj = json.loads(data)
  print (formatj)
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>Name : John 
  Address: 123street , USA 
  Phone No:  123456
  Gender: Male 
  
  Name : Jim 
  Address:  456street , USA 
  Phone No:  456899
  Gender: Male 
  </code></pre>
  
  <p>This is the same output which I have in my word file, but I don't think that this is in JSON format. </p>