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,
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 valuesa: [],# An array of numbera: [number],# An array of address objectc: [{street,city,state}],# A fixed sized array (len 5) of string that can accept maxLen of 10 charactersd: {[{string,maxLen:10}],len:5},# A fixed sized array (len 5) of stringe: {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.
# An array with an [] default
a: {array, default: [], optional: T},
# An array with a null default
b: {[string], default: N, optional: T, null: T}
---
# A variable sized array of string with minLen: 3
a: {[string], minLen: 3}
---
# A variable sized array of string witn maxLen:5
a: {[string], maxlen: 5}
---
# A fixed sized array with length 5
a: {[string], len: 5}
---
# An array set to null
a?*: {array, default: N}
# An array that will accept any values.
b: {[], null: T}
---
# Set an array to optional
a?: []
b?: array
# Assign optional value to an array using optional: T
b: {[], optional: T}
# Set an array to option using default and null
c: {[], default: N, null: T, default: T}
---
# Set an array type for a, b, c
a: array
b: {type: array}
c: {type: array, schema:[number]}
---
# Defining an array of numbers
numArray: [number]
---
[63, 45, 66, 80, 74]
# Defining an array of strings
stringArray: [string]
---
[English, Maths, Physics, Computer Science]
# An alphanumeric array with a schema
alphaNumArray: {array, schema: {any, anyOf: [string, int]}}
---
[1, a, 2, b, 3, c]
tags: [string, int]
---
[1, a, 2, b, 3, c]
# An array that will accept mixed values
mixedArray: [ ]
---
[one, T, { a:10, b: -Inf, NaN } ]
# Assigning default: [] to the array of string
~ optionalStringArray?: {[strings], default: [ ]}
---
~ [Eggs, Green salad] # String Array
~ # Default is empty array []
# Assigning default and schema to the array
object?: {array, default: [{N, N}], schema: [{ header*, footer*}]}
---
~ [{Hello, World}] # array of object
~ # default is array of null object
# A fixed sized array of string with len: 5
fixedSizedStringArray: {[string], len: 5}
---
[ Wings of Fire,
Ignited Minds,
Indomitable Spirit,
India 2020,
Turning Points ]
# A variable sized array of objects with maxLen: 4.
address:{
[{street: string, city: string, zip: {string, len: 5}],
maxLen: 4
}
---
[ {Bond street, New York, 50001},
{X street, Hollywood, 30001},
{Maple street, Tennessee, 80007},
{Union street, Montclair, 45003} ]