Skip to main content
A newer version of this page is available. .

JsonDataSource.Schema Property

Gets or sets the JsonDataSource‘s data schema.

Namespace: DevExpress.DataAccess.Json

Assembly: DevExpress.DataAccess.v19.2.dll

Declaration

[Browsable(false)]
[DefaultValue(null)]
public JsonSchemaNode Schema { get; set; }

Property Value

Type Default Description
JsonSchemaNode *null*

The data source schema’s root node.

Remarks

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.

Customize the Schema property to build a custom data source schema:

  1. Create a JsonSchemaNode class instance and set its properties.
  2. Use the JsonSchemaNode.Children property to specify the collection of child nodes.
  3. Assign the root node instance to the Schema property.

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;
        // ...
        public static JsonDataSource CreateDataSourceFromWeb() {
            var jsonDataSource = new JsonDataSource();
            // Specify the endpoint.
            jsonDataSource.JsonSource = new UriJsonSource(new Uri("http://northwind.servicestack.net/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;
            // Populate the data source with data.
            jsonDataSource.Fill();
            return 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.

See Also