corelibraries-devexpress-dot-dataaccess-dot-json-dot-jsondatasource-42058982.md
Gets or sets the JsonDataSource‘s data schema.
Namespace : DevExpress.DataAccess.Json
Assembly : DevExpress.DataAccess.v25.2.dll
NuGet Package : DevExpress.DataAccess
[Browsable(false)]
[DefaultValue(null)]
public JsonSchemaNode Schema { get; set; }
<Browsable(False)>
<DefaultValue(Nothing)>
Public Property Schema As JsonSchemaNode
| Type | Default | Description |
|---|---|---|
| JsonSchemaNode | null |
The data source schema’s root node.
|
Use this property to specify the data source schema. When the schema is specified, you can bind controls to data source fields.
If the Schema property is set to null ( Nothing in Visual Basic), the Fill method call provides both the schema and data. The schema is generated based on the provided data. The SchemaDiscoveryMaxItemCount property specifies how many records to analyze in order to build the schema.
Customize the Schema property to build a custom data source schema:
Note
If you modify the schema after you called the Fill method, call this method again to apply changes to the data.
In the following code, the Customers node’s schema is defined and added to the data source’s root node.
root: {
customers: [{
CustomerID
CompanyName
ContactTitle
}]
}
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports.UI;
public static JsonDataSource CreateDataSourceFromWeb() {
var jsonDataSource = new JsonDataSource();
// Specify the endpoint.
jsonDataSource.JsonSource = new UriJsonSource(
new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"));
var root = new JsonSchemaNode();
root.NodeType = JsonNodeType.Object;
var customers = new JsonSchemaNode() {NodeType=JsonNodeType.Array, Name="Customers", Selected=true };
customers.AddChildren(new[] {
new JsonSchemaNode(new JsonNode("CustomerID", true,
JsonNodeType.Property, typeof(string)))
{
DisplayName = "Customer ID" },
new JsonSchemaNode() {
Name = "CompanyName",
Selected = true,
NodeType = JsonNodeType.Property,
Type = typeof(string)
},
new JsonSchemaNode(new JsonNode("ContactTitle", true, JsonNodeType.Property, typeof(string))),
new JsonSchemaNode(new JsonNode("Address", false, JsonNodeType.Property, typeof(string)))
});
root.AddChildren(customers);
jsonDataSource.Schema = root;
// The schema is built, you do not have to call the Fill method to populate the Field List.
// The Designer calls the Fill method automatically when a document is generated for preview.
//jsonDataSource.Fill();
return jsonDataSource;
}
Imports System.Net
Imports DevExpress.DataAccess.Json
Imports DevExpress.XtraReports.UI
Public Shared Function CreateDataSourceFromWeb() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
' Specify the endpoint.
jsonDataSource.JsonSource = New UriJsonSource(
New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.json"))
Dim root = New JsonSchemaNode()
root.NodeType = JsonNodeType.Object
Dim customers = New JsonSchemaNode() With {.NodeType = JsonNodeType.Array, .Name = "Customers", .Selected = True}
customers.AddChildren({
New JsonSchemaNode(New JsonNode("CustomerID", True, JsonNodeType.Property,
GetType(String))) With {.DisplayName = "Customer ID"},
New JsonSchemaNode() With {.Name = "CompanyName", .Selected = True,
.NodeType = JsonNodeType.Property, .Type = GetType(String)},
New JsonSchemaNode(New JsonNode("ContactTitle", True, JsonNodeType.Property,
GetType(String))),
New JsonSchemaNode(New JsonNode("Address", False, JsonNodeType.Property,
GetType(String)))
})
root.AddChildren(customers)
jsonDataSource.Schema = root
' The schema is built, you do not have to call the Fill method to populate the Field List.
' The Designer calls the Fill method automatically when a document is generated for preview.
'jsonDataSource.Fill()
Return jsonDataSource
End Function
View Example: How to Create a Report Bound to JsonDataSource
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Schema property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
reporting-winforms-create-report-bound-to-json-data-source/CS/Form1.cs#L86
root.AddChildren(customers);
jsonDataSource.Schema = root;
#endregion
reporting-winforms-create-report-bound-to-json-data-source/VB/Form1.vb#L73
root.AddChildren(customers)
jsonDataSource.Schema = root
#End Region
See Also