Back to Devexpress

JSON Data Source

dashboard-401312-winforms-dashboard-winforms-designer-create-dashboards-in-the-winforms-designer-providing-data-json-data-source.md

latest7.1 KB
Original Source

JSON Data Source

  • Sep 24, 2025
  • 5 minutes to read

The Dashboard Designer allows you to connect to a JSON data source that retrieves data from a Web-service endpoint, text file, or a string in JSON format.

Important

The DashboardJsonDataSource object requires the System.Text.Json library. .NET projects do not require manual installation of the System.Text.Json package, as it is already included in the .NET environment. Set the DevExpress.DataAccess.Native.Json.JsonLoaderHelper.ProcessingLibrary property to NewtonsoftJson to use the Newtonsoft.Json library instead. Then, install the Newtonsoft.Json NuGet package.

You can read files from any directory by default. To protect your application, use the AccessSettings class to explicitly specify where data sources can be read from. To accomplish this, configure rules in the DataResources property to restrict file system access to specified folders. You can call the SetRules(IAccessRule[]) method when your application starts to specify rules before a dashboard control sets its rules. The SetRules(IAccessRule[]) method can be called only once at application startup. Otherwise, the method will raise an exception.

Create a New Data Connection

Follow the steps below to connect to the JSON data source:

  1. Click the New Data Source button in the Data Source ribbon tab.

  2. On the first page of the invoked Data Source Wizard dialog, specify whether you want to use an existing data connection or create a new data connection.

  3. On the next page, select JSON data and click Next.

Configure a New Data Connection

  1. On the next page, configure a new data connection.

Select Data Fields

  1. The “Select data fields” page allows you to include / exclude data fields used in a JSON data source.

Connect a Dashboard to the JSON Data Source in Code

  1. Create the DashboardJsonDataSource instance with a simple constructor.
  2. Use the JsonSource property to specify the JSON data location.
  3. Use the RootElement property to specify a root JSON node.
  4. Add the created data source to the dashboard’s Dashboard.DataSources collection.
  5. Assign the created data source to the dashboard item’s DataDashboardItem.DataSource property.

View Example: How to Bind a Dashboard to the JSON Data Source at Runtime

The code sample below illustrates how to retrieve JSON data from different sources:

csharp
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Json;
// ...
public void InitializeDashboard() {
    Dashboard dashboard = new Dashboard();
    DashboardJsonDataSource jsonDataSourceFromWeb = CreateJsonDataSourceFromWeb();
    DashboardJsonDataSource jsonDataSourceFromFile = CreateJsonDataSourceFromFile();
    DashboardJsonDataSource jsonDataSourceFromString = CreateJsonDataSourceFromString();

    dashboard.DataSources.Add(jsonDataSourceFromWeb);
    dashboard.DataSources.Add(jsonDataSourceFromFile);
    dashboard.DataSources.Add(jsonDataSourceFromString);
}

public static DashboardJsonDataSource CreateJsonDataSourceFromWeb()
{
    var jsonDataSource = new DashboardJsonDataSource();
    jsonDataSource.JsonSource = new UriJsonSource(new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
    jsonDataSource.RootElement = "Customers";
    return jsonDataSource;
}

public static DashboardJsonDataSource CreateJsonDataSourceFromFile()
{
    var jsonDataSource = new DashboardJsonDataSource();
    Uri fileUri = new Uri("customers.json", UriKind.RelativeOrAbsolute);
    jsonDataSource.JsonSource = new UriJsonSource(fileUri);
    jsonDataSource.RootElement = "Customers";
    return jsonDataSource;
}

public static DashboardJsonDataSource CreateJsonDataSourceFromString()
{
  var jsonDataSource = new DashboardJsonDataSource();
  string json = "{\"Customers\":[{\"Id\":\"ALFKI\",
  \"CompanyName\":\"Alfreds Futterkiste\",\"ContactName\":\"Maria Anders\",
  \"ContactTitle\":\"Sales Representative\",\"Address\":\"Obere Str. 57\",
  \"City\":\"Berlin\",\"PostalCode\":\"12209\",\"Country\":\"Germany\",
  \"Phone\":\"030-0074321\",\"Fax\":\"030-0076545\"}],\"ResponseStatus\":{}}";
  jsonDataSource.JsonSource = new CustomJsonSource(json);
  jsonDataSource.RootElement = "Customers";
  return jsonDataSource;
}
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.DataAccess.Json
' ...
Public Sub InitializeDashboard()
    Dim dashboard As New Dashboard()
    Dim jsonDataSourceFromWeb As DashboardJsonDataSource = CreateJsonDataSourceFromWeb()
    Dim jsonDataSourceFromFile As DashboardJsonDataSource = CreateJsonDataSourceFromFile()
    Dim jsonDataSourceFromString As DashboardJsonDataSource = CreateJsonDataSourceFromString()

    dashboard.DataSources.Add(jsonDataSourceFromWeb)
    dashboard.DataSources.Add(jsonDataSourceFromFile)
    dashboard.DataSources.Add(jsonDataSourceFromString)
End Sub

Public Shared Function CreateJsonDataSourceFromWeb() As DashboardJsonDataSource
    Dim jsonDataSource = New DashboardJsonDataSource()
    jsonDataSource.JsonSource = New UriJsonSource(New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"))
    jsonDataSource.RootElement = "Customers"
    Return jsonDataSource
End Function

Public Shared Function CreateJsonDataSourceFromFile() As DashboardJsonDataSource
    Dim jsonDataSource = New DashboardJsonDataSource()
    Dim fileUri As New Uri("customers.json", UriKind.RelativeOrAbsolute)
    jsonDataSource.JsonSource = New UriJsonSource(fileUri)
    jsonDataSource.RootElement = "Customers"
    Return jsonDataSource
End Function

Public Shared Function CreateJsonDataSourceFromString() As DashboardJsonDataSource
    Dim jsonDataSource = New DashboardJsonDataSource()
    Dim json As String = "{""Customers"":[{""Id"":""ALFKI"",""CompanyName"":""Alfreds Futterkiste"",""ContactName"":""Maria Anders"",""ContactTitle"":""Sales Representative"",""Address"":""Obere Str. 57"",""City"":""Berlin"",""PostalCode"":""12209"",""Country"":""Germany"",""Phone"":""030-0074321"",""Fax"":""030-0076545""}],""ResponseStatus"":{}}"
    jsonDataSource.JsonSource = New CustomJsonSource(json)
    jsonDataSource.RootElement = "Customers"
    Return jsonDataSource
End Function

See Also

Security Considerations in Windows Forms