Word to JSON conversion could be required in various cases when you need to export data in a Word document to JSON format programmatically. This article demonstrates how to easily convert the text in a Word document to JSON format from within your C# applications. You will also learn how to convert protected Word documents to JSON programmatically. So let’s proceed to convert Word to JSON in C#.
- Steps to Convert Word to JSON in C#
- C# Library to Convert Word to JSON - Free Download
- Convert Word to JSON in C#
- Convert Protected Word to JSON in C#
How to Convert Word to JSON in C#
For Word document to JSON conversion, 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 C#. For this, you need to install a couple of libraries that are mentioned in the following section.
C# Libraries to Convert Word to JSON
Aspose.Words for .NET is a feature-rich library that lets you create and process MS Word documents. We will use this library to export the content of a Word document to HTML. After that, we will use Aspose.Cells for .NET to save HTML content as a JSON file. The best thing is, you can use these libraries absolutely free.
You can either download the DLLs of both libraries or install them from NuGet.
Download DLL
Install via NuGet
PM> Install-Package Aspose.Cells
PM> Install-Package Aspose.Words
Convert DOC to JSON in C#
The following are the steps to convert Word to JSON in C#.
- Load the Word document using Aspose.Words.Document class.
- Save Word document as HTML using Document.Save() method.
- Load HTML file using Aspose.Cells.Workbook class.
- Convert document to JSON format using Workbook.Save() method.
The following code sample shows how to convert a Word DOC to JSON in C#.
C# 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 C#.
- Load the Word document using Aspose.Words.Document class.
- Use Aspose.Words.Loading.LoadOptions class to specify the password of Word document.
- Save Word document as HTML using Document.Save() method.
- Load HTML file using Aspose.Cells.Workbook class.
- Convert document to JSON format using Workbook.Save() method.
The following code sample shows how to convert a protected Word document to JSON in C#.
Free Word to JSON Conversion
You can get a free temporary license to convert Word documents to JSON format without evaluation limitations.
Explore C# DOC to JSON Converter
You can visit the documentation of Aspose.Words for .NET and Aspose.Cells for .NET to explore more about the libraries. In case you would have any questions, feel free to let us know via our forum.
Conclusion
In this article, you have learned how to convert Word to JSON in C#. Moreover, you have seen how to convert a password-protected Word document to JSON programmatically. You can easily integrate the provided code samples into your application for DOC to JSON conversion.