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.
# An array with an [] defaulta: {array,default: [],optional:T}, # An array with a null defaultb: {[string],default:N,optional:T,null:T}---
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.
# A variable sized array of string with minLen: 3a: {[string],minLen:3}---
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.
# A variable sized array of string witn maxLen:5a: {[string],maxlen:5}---
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.
# A fixed sized array with length 5a: {[string],len:5}---
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.
# An array set to null a?*: {array,default:N}# An array that will accept any values.b: {[],null:T}---
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
# Set an array to optionala?: []b?:array# Assign optional value to an array using optional: Tb: {[],optional:T}# Set an array to option using default and null c: {[],default:N,null:T,default:T}---
type
An array type can be specified as shown in the snippet below.
# Set an array type for a, b, ca:arrayb: {type:array}c: {type:array,schema:[number]}---
Examples
Some of the valid examples of members with array type are...
# Defining an array of numbersnumArray: [number] ---[63,45,66,80,74]
# Defining an array of stringsstringArray: [string] ---[English,Maths,Physics,Computer Science]
# An alphanumeric array with a schemaalphaNumArray: {array,schema: {any,anyOf: [string,int]}}---[1,a,2,b,3,c]
The above example can be simplified as,
tags: [string,int]---[1,a,2,b,3,c]
An array can have mixed values as shown in the snippet below.
# An array that will accept mixed valuesmixedArray: [ ] ---[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 arrayobject?: {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} ]
Nested Arrays
An array containing another array represents a nested array as shown in the code snippet.
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.