JSON to HTML Java

JSON is a standard text-based format that represents structured data based on JavaScript object syntax. It is commonly used to send data from the server to the client. In certain cases, we may need to directly export data from a JSON file to an HTML programmatically. In this article, we will learn how to convert a JSON file to HTML format using Java.

The following topics shall be covered in this article:

  1. JSON to HTML Converter Java API
  2. Convert JSON to HTML
  3. Convert JSON to HTML with Options

JSON to HTML Converter Java API

For converting JSON to HTML, we will be using the Aspose.Cells for Java API. It is a feature-rich, powerful and easy to use API to work with Microsoft Excel-associated worksheets within the Java applications. It can be used for comprehensive charting, scalable reporting, and reliable calculations.

The Workbook class of the API represents an Excel workbook. Each workbook or spreadsheet can contain multiple worksheets. It allows opening and saving native Excel files. It also provides some advanced features like copying data from other Workbooks, combining two Workbooks, and protecting the Excel spreadsheet. The save() method of this class allows saving the workbooks in the provided formats. The HtmlSaveOptions class of the API represents the options for saving the HTML file.

Please either downloads the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.

<repository>  
    <id>AsposeJavaAPI</id>  
    <name>Aspose Java API</name>  
    <url>https://repository.aspose.com/repo/</url>  
</repository>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells</artifactId>
    <version>22.6</version>
</dependency>

Convert JSON to HTML in Java

We can convert JSON file to HTML by following the steps given below:

  1. Load the JSON file using the Workbook class.
  2. Save the HTML file using the save() method. It takes the output HTML file path as an argument.

The code example given below shows how to convert a JSON file to HTML using Java.

Convert JSON to HTML in Java

Convert JSON to HTML with Options in Java

We can convert JSON file to HTML using advanced options by following the steps given below:

  1. Firstly, load the JSON file using the Workbook class.
  2. Next, create an instance of the HtmlSaveOptions class.
  3. After that, specify the required HTML save options, such as ExportGridLines.
  4. Finally, save the HTML file using the save() method. It takes the output HTML file path and the HtmlSaveOptions object as arguments.

The code example given below shows how to convert a JSON to HTML with advanced options using Java.

Convert JSON to HTML with Options in Java

Get a Free License

You can get a free temporary license to try the library without evaluation limitations.

Conclusion

In this article, we have learned how to convert JSON to HTML format programmatically in Java. We have also seen how to specify various options while converting JSON to HTML. Besides, you can learn more about Aspose.Cells for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also