Developers / Export Reports / Export Page/RDLX Reports / JSON Export
JSON Export

JavaScript Object Notation (JSON) is a text-based data format in which the data is stored in the hierarchical form. You can use the JsonRenderingExtension to render your report in this format.

JSON Rendering Properties

ActiveReports offers several options to control how reports render to JSON.

Property Description
Formatted Specifies whether to format the file with tabs and spaces for readability.
QuotePropertyNames Specifies whether to enclose property names in quotation marks.

Export Report using JSON Rendering Extension

The following steps provide an example of rendering a report in JSON format.

  1. Create a new or open an existing Windows Forms App in Visual Studio project.
  2. Go to the Project Explorer, right-click the project and select Add > New Item.
  3. Select ActiveReports 19 Standalone Report > Add and choose a report type, RDLX, RDLX Dashboard, or Page report and then click Finish.
  4. Add a reference to MESCIUS.ActiveReports.Export.Xml package in the project.
  5. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
  6. Add the following code inside the Form_Load event.

VB code. Paste INSIDE the Form Load event.
Copy Code
' Provide the Page report you want to render.
Dim rptPath As System.IO.FileInfo = New System.IO.FileInfo("..\..\..\Report1.rdlx")
Dim pageReport As GrapeCity.ActiveReports.PageReport = New GrapeCity.ActiveReports.PageReport(rptPath)

 

' Create an output directory.
Dim outputDirectory As New System.IO.DirectoryInfo("C:\MyJSON")
outputDirectory.Create()

' Provide settings for your rendering output.
Dim jsonSettings As New GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension.Settings()
jsonSettings.Formatted = True

' Set the rendering extension and render the report.
Dim jsonRenderingExtension As New GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension()

Dim outputProvider As New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name))
' Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = True

pageReport.Document.Render(jsonRenderingExtension, outputProvider, jsonSettings)
C# code. Paste INSIDE the Form Load event.
Copy Code
// Provide the Page report you want to render.
System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\..\Report1.rdlx");
GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);

// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyJSON");
outputDirectory.Create();

// Provide settings for your rendering output.
eReports.Export.Text.Page.JsonRenderingExtension.Settings jsonSettings = new
        GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension.Settings();

jsonSettings.Formatted = true;

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension jsonRenderingExtension = new
        GrapeCity.ActiveReports.Export.Text.Page.JsonRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory,
        System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));

// Overwrite output file if it already exists.
outputProvider.OverwriteOutputFile = true;

pageReport.Document.Render(jsonRenderingExtension, outputProvider, jsonSettings);