JSON Viewer using C# .NET - Render JSON

JSON is one of the favorite structured data formats of developers for passing information within applications. However, it is often required to convert JSON data into other formats for various reasons. In this article, we will see how to render JSON files into PDF format using C#. Additionally, we will convert the JSON files into JPG, PNG, and HTML formats within the .NET application using examples.

Today, we will separately see the C# way for how to render:

We have already discussed the following topics regarding JSON using C#:

Now, if you have not yet prepared the environment, let’s quickly get what we need for rendering JSON files.

JSON File Viewer – .NET API

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

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Viewer

JSON to PDF using C#

It is often required while sharing files to convert the JSON format to PDF format due to its high portability. The following steps show how to render JSON files in PDF format using C#.

  • Load the JSON file using the Viewer class.
  • Prepare the PDF rendering options using the PdfViewOptions class.
  • Use the View() method to render the JSON file as a PDF.

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

View JSON File as JPG, PNG, or HTML using C#

Likewise, you can convert JSON files into other formats. The following steps help you render the JSON files into different formats using C#.

  • 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. (You can use either embedded or external resources)
  • Use the View() method to render JSON files as HTML, JPG, or PNG.

Below are the C# examples that separately render JSON files into each format using the respective format options.

JSON to JPG using C#

The following C# code converts the JSON file into JPG format.

JSON to PNG using C#

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

JSON to HTML using C#

The following C# source code converts the JSON file into HTML format with embedded resources.

Similarly, you can also convert it to HTML 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 conclude, we learned to render the JSON files into other formats. Specifically, we converted the JSON Data files into PDF, JPG, PNG, and HTML formats using the C# examples.

You can develop your own JSON viewer application like Groupdocs.Viewer Online App.

To learn more about GroupDocs.Viewer for .NET, visit its documentation and source code from GitHub. For queries, contact us via the forum.

See Also