Convert JSON Format to DOC via C#

C# API to parse JSON to DOC without using Microsoft® Word

JSON Conversion via Java JSON Conversion via C++ JSON Conversion in Android Apps

 

By using Aspose.Total for .NET you can parse JSON to DOC within any .NET, C#, ASP.NET and VB.NET application in two simple steps. Firstly, by using Aspose.Cells for .NET , you can export JSON to PDF. After that, by using Aspose.Words for .NET , you can convert PDF to DOC.

Convert JSON Format to DOC via C#

  1. Create a new Workbook object and read valid JSON data from file
  2. Import JSON file to worksheet using JsonUtility class and Save it as PDF
  3. Load PDF document by using Document class
  4. Save the document to DOC format using Save method

Conversion Requirements

Install from the command line as nuget install Aspose.Total or via Package Manager Console of Visual Studio.

Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .

// create a Workbook object
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
// read JSON data from file
string jsonInput = File.ReadAllText("input.json");
// import JSON data to worksheet starting at cell A1
Utility.JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, new JsonLayoutOptions());
// save resultant file in PDF format
workbook.Save("output.pdf", SaveFormat.Pdf);
// load PDF with an instance of Document
var document = new Document("output.pdf");
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats
// call Save method while passing SaveFormat.Doc
document.Save("output.doc", Aspose.Words.SaveFormat.Doc);

Set Layout and Convert JSON Format to DOC via C#

While parsing JSON to DOC, you can also set layout options for your JSON using JsonLayoutOptions . It allows you to process Array as a table, ignore nulls, ignore array title, ignore object title, convert string to number or date, set date and number format, and set title style. All of these options allow you to present your data as per your needs. The following code snippet shows you how to set the layout options.

// create a Workbook object
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
// read JSON data from file
string jsonInput = File.ReadAllText("input.json");
// set JsonLayoutOptions to treat Arrays as Table
var options = new Aspose.Cells.Utility.JsonLayoutOptions();
options.ArrayAsTable = true;
options.IgnoreNull = true;
options.IgnoreObjectTitle = true;
options.IgnoreArrayTitle = true;
// import JSON data to worksheet starting at cell A1
Utility.JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, options);
// save resultant file in PDF format
workbook.Save("output.pdf", SaveFormat.Pdf);
// load PDF with an instance of Document
var document = new Document("output.pdf");
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats
// call Save method while passing SaveFormat.Doc
document.Save("output.doc", Aspose.Words.SaveFormat.Doc);

Parse JSON Format to DOC with Watermark

Using the API, you can also convert JSON to DOC with watermark. In order to add a watermark to your DOC document, you can first parse JSON file to PDF and add a watermark to it. In order to add a watermark, load the newly created PDF file using the Document class, create an instance of TextWatermarkOptions and set its properties, Call Watermark.SetText method and pass watermark text & object of TextWatermarkOptions. After adding the watermark, you can save the document to DOC.

// create a Workbook object
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
// read JSON data from file
string jsonInput = File.ReadAllText("input.json");
// import JSON data to worksheet starting at cell A1
Utility.JsonUtility.ImportData(jsonInput, worksheet.Cells, 0, 0, new JsonLayoutOptions());
// save resultant file in PDF format
workbook.Save("output.pdf", SaveFormat.Pdf);
// load PDF with an instance of Document
var document = new Document("output.pdf");
// create an instance of TextWatermarkOptions and set its properties
var waterMakroptions = new TextWatermarkOptions()
{
FontFamily = "Arial",
FontSize = 36,
Layout = WatermarkLayout.Horizontal,
IsSemitrasparent = false
};
// set watermark text with the object of TextWatermarkOptions
document.Watermark.SetText("CONFIDENTIAL", waterMakroptions);
// supports DOC, DOT, DOCM, DOTX, DOTX, FLATOPC, RTF, WordML, MOBI, CHM, ODT, OTT, PS, PCL, EPUB file formats
// call Save method while passing SaveFormat.Doc
document.Save("output.doc", Aspose.Words.SaveFormat.Doc);

Transforming JSON File to DOC Programmatically : Use Cases

JSON (JavaScript Object Notation) files are used to store data in a structured and easily readable format, making them ideal for creating dynamic web applications and APIs. However, when working with document-based formats, Microsoft Word documents (.doc) become essential for content creation and editing.

The conversion of JSON files into .doc formats is necessary to unlock the full potential of your content creation and editing capabilities. This conversion enables you to:

Use Cases:

  • Document Automation: Convert JSON files to create dynamic document templates, automate report generation, and reduce manual data entry.
  • Content Integration: Use .doc to integrate content from various sources, such as web scraping or API integrations, into a cohesive document format.
  • Collaboration Tools: Convert JSON files to enable real-time collaboration and commenting on documents using tools like Microsoft Word Online or Google Docs.
  • Data-Driven Content: Use .doc to create data-driven content, such as personalized emails or newsletters, that can be easily updated and customized.
  • Accessibility Features: Convert JSON files to add accessibility features to documents, such as text-to-speech functionality or high contrast mode.

Explore JSON Conversion Options with .NET

Convert JSON to POWERPOINT (Presentation Files)
Convert JSON to WORD (WordProcessing File Formats)
Convert JSON to APNG (Animated Portable Network Graphics)
Convert JSON to CHM (Compiled HTML Help File)
Convert JSON to DICOM (Digital Imaging and Communications in Medicine)
Convert JSON to DOCM (Microsoft Word 2007 Marco File)
Convert JSON to DOT (Microsoft Word Template Files)
Convert JSON to DOTX (Microsoft Word Template File)
Convert JSON to DXF (Autodesk Drawing Exchange Format)
Convert JSON to EMZ (Windows Compressed Enhanced Metafile)
Convert JSON to EPUB (Open eBook File)
Convert JSON to FLATOPC (Microsoft Word 2003 WordprocessingML)
Convert JSON to IMAGE (Image Files)
Convert JSON to JPEG2000 (J2K Image Format)
Convert JSON to MOBI (Open Ebook Format)
Convert JSON to ODP (OpenDocument Presentation Format)
Convert JSON to ODT (OpenDocument Text File Format)
Convert JSON to OTP (OpenDocument Standard Format)
Convert JSON to OTT (OpenDocument Template)
Convert JSON to PCL (Printer Command Language)
Convert JSON to POT (Microsoft PowerPoint Template Files)
Convert JSON to POTM (Microsoft PowerPoint Template File)
Convert JSON to POTX (Microsoft PowerPoint Template Presentation)
Convert JSON to PPS (PowerPoint Slide Show)
Convert JSON to PPSM (Macro-enabled Slide Show)
Convert JSON to PPSX (PowerPoint Slide Show)
Convert JSON to PPT (PowerPoint Presentation)
Convert JSON to PPTM (Macro-enabled Presentation File)
Convert JSON to PS (PostScript File)
Convert JSON to PSD (Photoshop Document)
Convert JSON to RTF (Rich Text Format)
Convert JSON to SVGZ (Compressed Scalable Vector Graphics)
Convert JSON to TGA (Truevision Graphics Adapter)
Convert JSON to WMF (Windows Metafile)
Convert JSON to WMZ (Compressed Windows Metafile)
Convert JSON to WORDML (Microsoft Word 2003 WordprocessingML)