Reporting - New JSON and XPO Data Sources (v18.2)

Reporting Team Blog
01 November 2018

Reports are almost always bound to data – the more flexible our Reporting solution is when it comes to supported data sources, the more use cases we can cover. For v18.2 we added two new data source types that you can choose in the Data Source Wizard of the Report Designer.

New Data Source Types

The JSON Data Source and the XPO Data Source are new in this release. Like other data source types, they are handled directly by the Reporting system. The Wizard creates components to represent the data sources and accommodate some settings, and these components are persisted and restored together with the layout and design information of a report. The names of the new components are JsonDataSource and XPObjectSource.

JSON Data in Reports

JSON is a simple text-based format that is directly compatible with JavaScript (hence the name JavaScript Object Notation - JSON), but in other languages you need to deserialize objects from JSON format to native types. The JsonDataSource does this job for you, but of course it needs to know where the data comes from. The first page of the Wizard allows you to specify a Web Service Endpoint URI, a filename or even a string with JSON content:

Choose the source of JSON data

For the next step, the Wizard analyzes the JSON data and shows the structure in a hierarchy. You can choose all nodes or a subset of them to define which parts of the JSON will be used as data for the report.

Schema of JSON data

It is possible to change the type of the JsonDataSource as well as the schema. Once the component comes up in the Field List tool window, right-click it and choose the items Edit… and Edit Schema… from the context menu to make changes.

Note that we use the Open Source library Newtonsoft.Json for our implementation. This library is the de-facto standard for JSON in .NET. The wizard detects whether your project already references it and suggests to install the required NuGet package if necessary.

Installing Newtonsoft.Json

JSON Data Access from Code

If you would like to set up access to JSON data from code, use the specific types depending on the source of your data. For instance, to access data from a web service:

using DevExpress.DataAccess.Json;

...

var dataSource = new JsonDataSource();
ds.JsonSource = new UriJsonSource(new Uri("https://..."));

XtraReport report = ...;
report.DataSource = dataSource;

As a side note, the JsonDataSource is not limited to Reporting. Continuing from the sample code above, you can also use it for a Data Grid, for instance:

...
dataSource.Fill();
myDataGrid.DataSource = dataSource;

A Limitation

In this initial implementation of the JsonDataSource, we do not support token-based authentication. We are interested in your feedback – do you require this authentication support?

Access to XPO Data

eXpress Persistent Objects (XPO) is our own ORM product. You can find more information about it here if you’re curious. To work with XPO data in your own project you need to add persistent types, for instance using the XPO Data Model Wizard or a project item template.

If you select the XPO Data Source type in the Report Data Source Wizard, the next page will show the XPO persistent types that have been found in your project. (Note that you may need to build your solution in case the list doesn’t show all the types you expected!)

Choose an XPO entity

Once you have selected the XPO persistent type for your report, the further process is similar to the one described in our tutorial Bind a Report to a Database. You need to specify connection settings and then start to design your report.

The XPObjectSource component created by the Data Source Wizard is a standard XPO binding component. It has several properties you may want to configure, for example for server-side filtering of the queried data.

XPObjectSource settings

A cool XPO feature is the support for server-side calculated properties. You can add new properties in the editor for the Properties collection on the XPObjectSource and define PropertyExpressions for them.

XPO Properties collection editor

Your Feedback is Valuable!

We would like to hear what you think about these new features. Of course you can leave comments below or get back to us in the Support Center, but we would very much appreciate your responses to this quick survey:

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.