PDF download Download Article
Straightforward ways to convert unformatted text into usable JSON notation
PDF download Download Article

This wikiHow will teach you how to convert TXT to JSON using a built-in converter with Microsoft Visual Studio or a web browser with AnyConv. With AnyConv, you're limited to a file size of 50mb.

Quick Steps to Convert a Text File to JSON

If you have a small text file to convert (under 50mb) you can use AnyConv, a website that can convert many different filetypes. Simply upload your TXT file and select to convert it to JSON. If you're trying to convert a text file to JSON that's over 50mb, you'll need to use Microsoft Visual Studio.

Method 1
Method 1 of 2:

Using a Browser

PDF download Download Article
  1. Go to https://anyconv.com/txt-to-json-converter/ in a web browser. You can use any web browser to convert TXT to JSON.
  2. It's centered in the page; doing so will bring up your file manager.
    Advertisement
  3. Your TXT file needs to be smaller than 50mb to do this.
  4. The drop-down should already display "JSON" as the file type you're converting to.
    • The conversion process may take a while depending on the size of the file and your internet connection.
  5. Your file manager will open for you to choose a save location and file name before saving.
  6. Advertisement
Method 2
Method 2 of 2:

Using Visual Studio

PDF download Download Article
  1. 1
    Open the TXT document in Microsoft Visual Studio. You'll find this program in your Start menu or the Applications folder in Finder.
  2. 2
    Enter the following code after your TXT:
       # 
       Python 
       program 
       to 
       convert 
       text 
       [[ 
       Image 
       : 
       Convert 
       Txt 
       to 
       Json 
       Step 
       6 
       Version 
       2. 
       jpg 
       | 
       center 
       ]] 
       # 
       file 
       to 
       JSON 
       import 
       json 
       [[ 
       Image 
       : 
       Convert 
       Txt 
       to 
       Json 
       Step 
       7 
       Version 
       2. 
       jpg 
       | 
       center 
       ]] 
       # 
       the 
       file 
       to 
       be 
       converted 
       to 
       [[ 
       Image 
       : 
       Convert 
       Txt 
       to 
       Json 
       Step 
       8 
       Version 
       2. 
       jpg 
       | 
       center 
       ]] 
       # 
       json 
       format 
       filename 
       = 
       ' 
       EXAMPLE 
       . 
       txt 
       ' 
       # 
       dictionary 
       where 
       the 
       lines 
       from 
       # 
       text 
       will 
       be 
       stored 
       dict1 
       = 
       {} 
       # 
       creating 
       dictionary 
       with 
       open 
       ( 
       filename 
       ) 
       as 
       fh 
       : 
       for 
       line 
       in 
       fh 
       : 
       # 
       reads 
       each 
       line 
       and 
       trims 
       of 
       extra 
       the 
       spaces 
       # 
       and 
       gives 
       only 
       the 
       valid 
       words 
       command 
       , 
       description 
       = 
       line 
       . 
       strip 
       (). 
       split 
       ( 
       None 
       , 
       1 
       ) 
       dict1 
       [ 
       command 
       ] 
       = 
       description 
       . 
       strip 
       () 
       # 
       creating 
       json 
       file 
       # 
       the 
       JSON 
       file 
       is 
       named 
       as 
       test1 
       out_file 
       = 
       open 
       ( 
       "test1.json" 
       , 
       "w" 
       ) 
       json 
       . 
       dump 
       ( 
       dict1 
       , 
       out_file 
       , 
       indent 
       = 
       4 
       , 
       sort_keys 
       = 
       False 
       ) 
       out_file 
       . 
       close 
       () 
      
    • You need to change the first filename listed to your TXT file; the second filename will be the name of the converted file, so you might need to change that name too. This code example taken from: https://www.geeksforgeeks.org/convert-text-file-to-json-in-python/ .
  3. 3
    Save the file. You can either use the keyboard shortcut ( Ctrl/Cmd + S ) to save or navigate to File > Save .
  4. Advertisement


Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Article Summary X

      1. Go to https://anyconv.com/txt-to-json-converter/ in a web browser.
      2. Click Choose File .
      3. Navigate to and double-click to open your TXT file.
      4. Click Convert .
      5. Click Download .

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 75,055 times.

      Is this article up to date?

      Advertisement