Skip to main content

JsonDataSource.LoadSchema(Type) Method

Creates the data source schema from the provided type.

Namespace: DevExpress.DataAccess.Json

Assembly: DevExpress.DataAccess.v23.2.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

public JsonSchemaNode LoadSchema(
    Type type
)

Parameters

Name Type Description
type Type

The type used to create the schema.

Returns

Type Description
JsonSchemaNode

The created data source schema.

Remarks

Use this method to specify a JSON data source schema without the need to read data from the endpoint. This method creates a data source field for each public property from the specified type parameter. Private, protected, and internal properties are ignored. A property’s type is used to specify the field type.

Note

Members of the specified type should not be of the same type (or an inherited type) to avoid the stack overflow exception.

Example

The code sample below creates a new JSON data source and uses the JsonDataObject and Customer types to specify the data source schema.

Data Source Schema

using DevExpress.DataAccess.Json;
// ...
public class JsonDataObject
{
    public Customer[] Customers { get; set; }
}
public class Customer
{
    // A public property shown in the data source field list.
    public string CompanyName { get; set; }
    // A private property not shown in the data source field list.
    private string ContactName { get; set; }
}
JsonDataSource dataSource = new JsonDataSource();
dataSource.JsonSource = new UriJsonSource()
{
    Uri = new Uri(@"https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json")
};
// Create the data source schema from the JsonDataObject type.
dataSource.Schema = dataSource.LoadSchema(typeof(JsonDataObject));
See Also