Convert Word to JSON in Java

In certain cases, you need to export the content of a Word document to JSON file programmatically. To achieve that, this article provides a simple guide on how to convert the text in a Word document to JSON format from within your Java applications. You will also learn how to convert protected Word documents to JSON programmatically. So let’s proceed to convert Word to JSON in Java.

How to Convert Word to JSON in Java

To convert a Word document to JSON format, we need to perform the following steps:

  • Load the Word 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 Word 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 Word document 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 Word to JSON in Java

The following are the steps to convert Word to JSON in Java.

The following code sample shows how to convert a Word document to JSON in Java.

Java Convert Protected Word to JSON

You can also load the protected Word documents using their passwords and convert them to JSON format. The following are the steps to convert a protected Word document to JSON in Java.

The following code sample shows how to convert a protected Word document to JSON in Java.

Java Word 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 Word to JSON in Java. Moreover, you have seen how to convert a password-protected Word 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.

See Also