I have written a script on Linux which does some operations on a text file. The output is a clean text file as expected. The first lines are as below:
Hamlet 
William Shakespeare 
Edited Barbara B Mowat Paul Werstine 
Michael Poston Rebecca Niles 
Folger Shakespeare Library 
httpwwwfolgerdigitaltextsorgchapter5playHam 
Created Jul 31 2015 FDT version 092 
Characters Play 
line 17 POLONIUS father Ophelia Laertes councillor King Claudiusthis line substituted  
GHOST 
How can I return the output text file as json in a way that each two following words in the text will be the key/value pair? The word that has no word afterwards should be assigned a value of null.
 
     
    