JSON Viewer using Java - Render JSON

The self-describing, easy-to-understand, and easy-to-parse, JSON format is one of the ideal choices to interchange data in web services. With this huge usage, it is often required to convert JSON data format into other formats for various requirements. In this article, we will see how to render JSON files into PDF format in Java. Furhter, we will also convert the JSON files into JPG, PNG, and HTML formats within the Java application.

Today, we will separately see how to render:

We have already discussed the following topics regarding JSON:

Just in case, if you are not having the updated environment, let’s quickly get what is needed for JSON rendering.

JSON File Viewer – Java API

GroupDocs offers document viewer API for Java applications that allows rendering various file formats into PDF, JPG, PNG, and HTML formats. I will use this GroupDocs.Viewer for Java to view a JSON file by rendering it to other mentioned formats using source code examples.

You can download the JAR file from the downloads section or use the latest repository and dependency Maven configurations within your Java applications.

<repository>
    <id>groupdocs-artifacts-repository</id>
    <name>GroupDocs Artifacts Repository</name>
    <url>https://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
    <groupId>com.groupdocs</groupId>
    <artifactId>groupdocs-viewer</artifactId>
    <version>22.9</version>
</dependency>

JSON to PDF using Java

PDF format is famous for its portability and it is often required while sharing files. The following steps show how to render JSON files in PDF format using Java.

  • Load the JSON file using the Viewer class.
  • Prepare the PDF rendering options using the PdfViewOptions class.
  • Convert the JSON file to PDF by just calling the view() method.

The following Java code example renders the JSON files into PDF format.

View JSON File as JPG, PNG, or HTML using Java

Similarly, other formats can be obtained from a JSON file. The following steps help you render the JSON files into different formats using Java.

  • Load the JSON file using the Viewer class.
  • Prepare the rendering options according to the conversion format:
    • JPG rendering uses the JpgViewOptions class.
    • PNG rendering requires the PngViewOptions class.
    • HTML rendering needs the HtmlViewOptions class. There are different additional options while converting JSON to HTML:
      • Convert to HTML with embedded resources.
      • JSON to HTML with external resources.
      • Convert to responsive HTML.
  • Use the view() method to render JSON files as HTML, JPG, or PNG files.

Below Java examples separately render JSON files into each format using the respective conversion options.

JSON to JPG using Java

The following Java code converts the JSON file into JPG format.

JSON to PNG using Java

The following code converts the JSON file into PNG format using Java.

JSON to Responsive HTML using Java

The following Java source code converts the JSON file into Responsive HTML with embedded resources. Similarly, you can also convert it with external resources using the forExternalResources method.

Get a Free API License

You can get a free temporary license to use the API without the evaluation limitations to build an online JSON file viewer.

Conclusion

To sum up, we learned to render the JSON files into other formats. Specifically, we converted the JSON Data files into PDF, JPG, and PNG in Java. Finally, we learned to render the JSON as responsive HTML with either external or embedded resources using the Java example.

I hope, this will boost you to develop a JSON viewer Java application like Groupdocs.Viewer Online App.

You can learn more about GroupDocs.Viewer for Java from its documentation and GitHub examples. For queries, contact us via the forum.

See Also