Array

An Internet Object array can be defined with the members such as type, default, len, minLen, maxLen, optional and null. Schema of the array TypeDef should be written as,

TypeDef Schema

schema?   : {[$type, $memberdef, [any]], default:[any]}
default?  : array,
minLen?   : {int, minLen: 0},
maxLen?   : {int, minLen},
len?      : {int, minLen: 0},
null?     : {bool, F}
optional? : {bool, F}
type?     : {string, choices:[array]}
---

The TypeDef schema ensures the validity of array MemberDefs.

schema

The first member of the internet object array is a schema. When the schema is defined all array items must be validated against the schema. The code snippet demonstrates how the array can be defined with the schema.

# An array that can hold any values
a: [],

# An array of number
a: [number],

# An array of address object
c: [{street, city, state}],

# A fixed sized array (len 5) of string that can accept maxLen of 10 characters
d: {[{string, maxLen:10}], len: 5},

# A fixed sized array (len 5) of string
e: {default: [], schema: {[string], len: 5}, optional: T}
---

default

The next member in the array typedef is default . Here is how the default values can be defined for an array.

minLen

The value of minLen must be a non-negative integer. The array instance is valid only if, number of items in the array will be greater than or equal to the value of minLen. The code snippet shows how to define minLen for an array.

maxLen

The value of maxlen must be a non-negative integer. The array instance is valid only if, number of items in the array will be less than or equal to the value of the maxlen. Here the code snippet shows how to define maxLen for an array.

len

The next member in the array typedef is length represented as len , it must be a non-negative integer. The Array instance is valid only if, the number of items in the array will be exactly equal to the value of len. Here is how the len can be defined for an array.

The len has higher precedence over minLen and maxLen constraints. That is when the len is set, the implementations must ignore minLen and maxLen constraints.

null

An array when set to null will accept null values. Here the code snippet demonstrates the way how an array can accept a null value.

optional

A member of an array type can be set to optional. Here a code snippet demonstrates different ways how an array can be set to optional

type

An array type can be specified as shown in the snippet below.

Examples

Some of the valid examples of members with array type are...

The above example can be simplified as,

An array can have mixed values as shown in the snippet below.

Nested Arrays

An array containing another array represents a nested array as shown in the code snippet.

Multidimensional Array

A multidimensional array is an array with more than one dimension. Two and three-dimensional arrays are called multidimensional arrays. Here is the code snippet that demonstrates how a multidimensional array is represented.

Last updated

Was this helpful?