In certain cases, you need to export the content of a Word DOCX to JSON file programmatically. To achieve that, this article provides a simple guide on how to convert the text in a DOCX document to JSON format from within your Java applications. You will also learn how to convert protected DOCX documents to JSON programmatically. So let’s proceed to convert DOCX to JSON in Java.
- Steps to Convert DOCX to JSON in Java
- Java Library to Convert DOCX to JSON - Free Download
- Convert DOCX to JSON in Java
- Convert Protected DOCX to JSON in Java
How to Convert DOCX to JSON in Java
To convert a DOCX document to JSON format, we need to perform the following steps:
- Load the DOCX 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 DOCX 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 DOCX 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 DOCX to JSON in Java
The following are the steps to convert DOCX to JSON in Java.
- Load the DOCX document using com.aspose.words.Document class.
- Save DOCX 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 DOCX document to JSON in Java.
Java Convert Protected DOCX to JSON
You can also load the protected DOCX documents using their passwords and convert them to JSON format. The following are the steps to convert a protected DOCX document to JSON in Java.
- Load the DOCX document using com.aspose.words.Document class.
- Use com.aspose.words.LoadOptions class to specify the password of DOCX document.
- Save DOCX 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 DOCX document to JSON in Java.
Java DOCX 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 DOCX to JSON in Java. Moreover, you have seen how to convert a password-protected DOCX 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.