# Serializing and Deserializing Report Definitions

**Telerik Reporting** supports serialization/deserialization of the report definition as plain **XML** or **JSON**. The `TRDX`, `TRDJ`, and `TRDP` files are declarative report definitions:

* `TRDX` is a self-contained XML report definition. All embedded images are serialized in the XML file.
* `TRDJ` is a self-contained JSON report definition. All embedded images are serialized in the JSON file.
* `TRDP` is a ZIP archive containing the report definition as XML by default, but it can hold it as JSON too. It may also contain resources like image and localization files packed in the archive.

The report serialization/deserialization is useful in various scenarios and opens many possibilities that are not easily accomplished otherwise. For example, this allows adding or modifying reports in your application without recompiling or redeploying it. Another typical scenario is saving/loading dynamically generated report definitions or transferring them over the network.

> To better handle report definition resources, we also provide a [ReportPackager](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.reportpackager) that serializes the report definition in XML or JSON and packages it together with its resources in a file with zip compression. For more information, see [Package Report Definition](https://www.telerik.com/products/reporting/documentation/embedding-reports/program-the-report-definition/package-report-definition).

## Class Report Definition

The **XML** serialization/deserialization of report definitions is achieved through the dedicated [ReportXmlSerializer](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.xmlserialization.reportxmlserializer) class.

The **JSON** serialization/deserialization of report definitions is achieved through the dedicated [ReportJsonSerializer](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.jsonserialization.reportjsonserializer) class.

To illustrate how a report is serialized and deserialized, let us start with a simple dynamically generated class report definition:

```C#
var report = new Report1();

report.Width = Telerik.Reporting.Drawing.Unit.Inch(4);

var detailSection = new Telerik.Reporting.DetailSection();

detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);
report.Items.Add(detailSection);

var numberTextBox = new Telerik.Reporting.TextBox();

numberTextBox.Value = "=Fields.ProductNumber";
numberTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(0);
numberTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0);
numberTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2);
numberTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);
detailSection.Items.Add(numberTextBox);

var nameTextBox = new Telerik.Reporting.TextBox();

nameTextBox.Value = "=Fields.Name";
nameTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(2);
nameTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0);
nameTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2);
nameTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2);
detailSection.Items.Add(nameTextBox);

var dataSource = new Telerik.Reporting.SqlDataSource();

dataSource.ConnectionString = "Data Source=.\\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True";
dataSource.SelectCommand = "select ProductNumber, Name from Production.Product";
report.DataSource = dataSource;
```

```VB.NET
Dim report As New Report1()

report.Width = Telerik.Reporting.Drawing.Unit.Inch(4)

Dim detailSection As New Telerik.Reporting.DetailSection()

detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2)
report.Items.Add(detailSection)

Dim numberTextBox As New Telerik.Reporting.TextBox()

numberTextBox.Value = "=Fields.ProductNumber"
numberTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(0)
numberTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0)
numberTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2)
numberTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2)
detailSection.Items.Add(numberTextBox)

Dim nameTextBox As New Telerik.Reporting.TextBox()

nameTextBox.Value = "=Fields.Name"
nameTextBox.Left = Telerik.Reporting.Drawing.Unit.Inch(2)
nameTextBox.Top = Telerik.Reporting.Drawing.Unit.Inch(0)
nameTextBox.Width = Telerik.Reporting.Drawing.Unit.Inch(2)
nameTextBox.Height = Telerik.Reporting.Drawing.Unit.Inch(0.2)
detailSection.Items.Add(nameTextBox)

Dim dataSource As New Telerik.Reporting.SqlDataSource()

dataSource.ConnectionString = "Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True"
dataSource.SelectCommand = "select ProductNumber, Name from Production.Product"
report.DataSource = dataSource
```

> note **Report1** is a derivative of the basic [Report class](https://www.telerik.com/products/reporting/documentation/api/telerik.reporting.report). A similar implementation can be found in the installation folder of the Telerik Reporting product, usually located at the following path: *Progress\Telerik Reporting 2026 Q4\Examples\CSharp.NET Framework\ReportLibrary*. You can refer to the **ProductCatalog** implementation. However, the code is valid for the basic **Report** implementation as well. It will contain a more simplified design with just the text boxes added to the report.

## Serialize to XML

The following sample code snippet demonstrates how to serialize the above report definition to an XML file:

```C#
using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("SerializedReport.xml"))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    xmlSerializer.Serialize(xmlWriter, report);
}
```

```VB.NET
Using xmlWriter As System.Xml.XmlWriter = System.Xml.XmlWriter.Create("SerializedReport.xml")
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    xmlSerializer.Serialize(xmlWriter, report)
End Using
```

## Deserialize from XML

The corresponding code that can be used to deserialize the report definition from the file is shown below:

```C#
System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;

using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("Report1.xml", settings))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)
        xmlSerializer.Deserialize(xmlReader);
}
```

```VB.NET
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True

Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create("Report1.xml", settings)
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)
End Using
```

and the resulting XML file would look like this:

## XML Report Definition

```XML
﻿<Report DataSourceName="sqlDataSource1" Width="4in" Name="userReport1" xmlns="http://schemas.telerik.com/reporting/2012/2">
  <DataSources>
    <SqlDataSource ConnectionString="Data Source=.\SqlExpress;Initial Catalog=AdventureWorks;Integrated Security=True" SelectCommand="select ProductNumber, Name from Production.Product" Name="sqlDataSource1" />
  </DataSources>
  <Items>
    <DetailSection Height="0.2in" Name="detailSection1">
      <Items>
        <TextBox Value="=Fields.ProductNumber" Size="2in, 0.2in" Location="0in, 0cm" Name="textBox1" />
        <TextBox Value="=Fields.Name" Size="2in, 0.2in" Location="2in, 0cm" Name="textBox2" />
      </Items>
    </DetailSection>
  </Items>
  <PageSettings>
    <PageSettings PaperKind="Letter" Landscape="False">
      <Margins>
        <MarginsU Left="1in" Right="1in" Top="1in" Bottom="1in" />
      </Margins>
    </PageSettings>
  </PageSettings>
</Report>
```

## Serialize to JSON

> note Serializing and deserializing JSON report definitions requires the 'Telerik.Reporting.JsonSerialization' assembly, which is not part of the 'Telerik.Reporting' assembly. To do this, install the 'Telerik.Reporting.JsonSerialization' NuGet package (or add a reference to 'Telerik.Reporting.JsonSerialization.dll') and make sure it is deployed next to 'Telerik.Reporting.dll'.

The following sample code snippet demonstrates how to serialize the above report definition to a JSON file:

```C#
using (System.IO.Stream stream = new System.IO.FileStream("Report.json", System.IO.FileMode.Create))
{
    Telerik.Reporting.JsonSerialization.ReportJsonSerializer jsonSerializer =
        new Telerik.Reporting.JsonSerialization.ReportJsonSerializer();

    jsonSerializer.Serialize(stream, report);
}
```

```VB.NET
Using stream As System.IO.Stream = New System.IO.FileStream("Report.json", System.IO.FileMode.Create)
    Dim jsonSerializer As New Telerik.Reporting.JsonSerialization.ReportJsonSerializer()

    jsonSerializer.Serialize(stream, report)
End Using
```

## Deserialize from JSON

The corresponding code that can be used to deserialize the report definition from the file is shown below:

```C#
using (System.IO.FileStream fileStream = new System.IO.FileStream("Report1.json", System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
    Telerik.Reporting.JsonSerialization.ReportJsonSerializer jsonSerializer =
        new Telerik.Reporting.JsonSerialization.ReportJsonSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)
        jsonSerializer.Deserialize(fileStream);
}
```

```VB.NET
Using fileStream As New System.IO.FileStream("Report1.json", System.IO.FileMode.Open, System.IO.FileAccess.Read)
    Dim jsonSerializer As New Telerik.Reporting.JsonSerialization.ReportJsonSerializer()

    Dim report As Telerik.Reporting.Report = DirectCast(jsonSerializer.Deserialize(fileStream), Telerik.Reporting.Report)
End Using
```

## JSON Report Definition

The resulting JSON file would look like this, if unminified:

```JSON
{
    "$schema": "http://schemas.telerik.com/reporting/2026/3.0",
    "NetType": "Report",
    "DataSource": "sqlDataSource1",
    "Width": "4in",
    "Name": "userReport1",
    "DataSources": [
        {
            "NetType": "SqlDataSource",
            "QueryDesignerState": "null",
            "ParameterValues": "null",
            "ConnectionString": "RGF0YSBTb3VyY2U9LlxTcWxFeHByZXNzO0luaXRpYWwgQ2F0YWxvZz1BZHZlbnR1cmVXb3JrcztJbnRlZ3JhdGVkIFNlY3VyaXR5PVRydWU=",
            "SelectCommand": "select ProductNumber, Name from Production.Product",
            "Name": "sqlDataSource1"
        }
    ],
    "Items": [
        {
            "NetType": "DetailSection",
            "Height": "0.2in",
            "Name": "detailSection1",
            "Items": [
                {
                    "NetType": "TextBox",
                    "Width": "2in",
                    "Height": "0.2in",
                    "Left": "0in",
                    "Top": "0cm",
                    "Value": "=Fields.ProductNumber",
                    "Name": "textBox1"
                },
                {
                    "NetType": "TextBox",
                    "Width": "2in",
                    "Height": "0.2in",
                    "Left": "2in",
                    "Top": "0cm",
                    "Value": "=Fields.Name",
                    "Name": "textBox2"
                }
            ]
        }
    ],
    "PageSettings": {
        "PaperKind": "Letter",
        "Landscape": false,
        "ColumnCount": 1,
        "ColumnSpacing": "0in",
        "Margins": {
            "NetType": "MarginsU",
            "Left": "1in",
            "Right": "1in",
            "Top": "1in",
            "Bottom": "1in"
        }
    }
}
```
