[]
        
(Showing Draft Content)

Schema Type

The type property of ISchemaOption defines how the data source is parsed.

It determines how the data value provided in IDataSourceOption is interpreted during fetch().

If type is not specified, the default value is "json".

const table = dataManager.addTable("products", {
    data: [
        { id: 1, name: "Laptop", price: 1200 }
    ],
    schema: {
        type: "json"
    }
});

Supported Types

The following values are supported:

Type

Description

"json"

Parses the data as a JSON array (default).

"csv"

Parses the data as a CSV string.

"xml"

Parses the data as an XML string.

"columnJson"

Parses column-oriented JSON data.

JSON (Default)

When type is "json" (or not specified):

  • data should be an array of objects.

  • Columns are automatically inferred from object keys if schema.columns is not defined.

Example:

const table = dataManager.addTable("employees", {
    data: [
        { id: 1, name: "Alice" },
        { id: 2, name: "Bob" }
    ]
});

No additional configuration is required.

CSV

When using "csv":

  • data must be a CSV string.

  • The string is parsed during fetch().

Example:

const table = dataManager.addTable("orders", {
    data: `id,name,amount
1,Alice,100
2,Bob,200`,
    schema: {
        type: "csv"
    }
});

If type is not set to "csv", the string will not be parsed as CSV.

XML

When using "xml":

  • data must be an XML string.

  • Parsing occurs during fetch().

  • In most cases, dataPath must be specified to locate the record collection.

Example:

const table = dataManager.addTable("orders", {
    data: `
<root>
    <row><id>1</id><name>Alice</name></row>
    <row><id>2</id><name>Bob</name></row>
</root>
`,
    schema: {
        type: "xml",
        dataPath: "root.row"
    }
});

See DataPath of Schema for details on selecting the record collection from parsed XML data.

ColumnJson

When using "columnJson":

  • data should be an object whose properties represent columns.

  • Each property contains an array of values.

  • Rows are constructed by aligning values by index.

Example:

const table = dataManager.addTable("employees", {
    data: {
        id: [1, 2, 3],
        name: ["Alice", "Bob", "Cindy"],
        age: [24, 26, 25]
    },
    schema: {
        type: "columnJson"
    }
});

During fetch(), the column-oriented structure is converted into row-based records.

When Schema Type Is Required

You must explicitly specify schema.type when:

  • The data value is a CSV string.

  • The data value is an XML string.

  • The data value is column-oriented JSON.

For standard JSON arrays, specifying "json" is optional.


This property only affects how data is parsed.

Column definitions, data behavior, and hierarchical structure are configured separately within schema.