In certain cases, you need to export the content of a Word DOC to JSON file programmatically. To achieve that, this article provides a simple guide on how to convert the text in a DOC document to JSON format from within your Java applications. You will also learn how to convert protected DOC documents to JSON programmatically. So let’s proceed to convert DOC to JSON in Java.
- Steps to Convert DOC to JSON in Java
- Java Library to Convert DOC to JSON - Free Download
- Convert DOC to JSON in Java
- Convert Protected DOC to JSON in Java
How to Convert DOC to JSON in Java
To convert a DOC document to JSON format, we need to perform the following steps:
- Load the DOC document.
- Convert it to HTML format.
- Save HTML file in JSON format.
Let’s see how to perform these steps programmatically in Java. For this you need to install two libraries that are mentioned in the following section.
Java Libraries to Convert DOC to JSON - Free Download
Aspose.Words for Java is a powerful library that allows you to create and process MS Word documents. We will use this library to export the content of a DOC file to HTML. Then, we will use Aspose.Cells for Java to save HTML content as a JSON file. You can either download the JARs of both libraries or install them using the Maven configurations.
Download JAR
Install via Maven
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>22.7</version>
<classifier>jdk17</classifier>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>22.7</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
Convert DOC to JSON in Java
The following are the steps to convert DOC to JSON in Java.
- Load the DOC document using com.aspose.words.Document class.
- Save DOC document as HTML using Document.Save() method.
- Load HTML file using com.aspose.cells.Workbook class.
- Convert document to JSON format using Workbook.Save() method.
The following code sample shows how to convert a DOC document to JSON in Java.
Java Convert Protected DOC to JSON
You can also load the protected DOC documents using their passwords and convert them to JSON format. The following are the steps to convert a protected DOC document to JSON in Java.
- Load the DOC document using com.aspose.words.Document class.
- Use com.aspose.words.LoadOptions class to specify the password of DOC document.
- Save DOC document as HTML using Document.Save() method.
- Load HTML file using com.aspose.cells.Workbook class.
- Convert document to JSON format using Workbook.Save() method.
The following code sample shows how to convert a protected DOC document to JSON in Java.
Java DOC to JSON Converter Libraries - Get a Free License
You can get a free temporary license to use the libraries without evaluation limitations.
Conclusion
In this article, you have learned how to convert DOC to JSON in Java. Moreover, you have seen how to convert a password-protected DOC document to JSON programmatically. Besides, you can visit the documentation of Aspose.Words for Java and Aspose.Cells for Java to explore other features. In case you would have any questions, feel free to let us know via our forum.