Indicates the current length of the array. This value can be both read and set. If it is set to a smaller value, the array is truncated. Any element beyond the new smaller size of the array is treated as if you call the JsonArray:Remove( ) on them. If this value is set to a larger size, the array is extended with null values as if JsonArray:AddNull( ) was called.

Data type: INTEGER

Access: PUBLIC Readable/Writeable

Applies to: Progress.Json.ObjectModel.JsonArray class

Examples

The following example shows the current length of the array after adding elements.

USING Progress.Json.ObjectModel.* FROM PROPATH.
VAR JsonArray Ja.

ja = NEW JsonArray().
ja:Add("A").
ja:Add("B").

MESSAGE "Length =" ja:Length VIEW-AS ALERT-BOX.
/* Result: Length = 2 */

The following example shows how setting the Length smaller, truncates the array.

/* Set Length smaller -> truncates the array */
USING Progress.Json.ObjectModel.* FROM PROPATH.
VAR JsonArray ja.
VAR CHARACTER  cJson.

ja = NEW JsonArray().
ja:Add("A").
ja:Add("B").
ja:Add("C").

ja:Length = 1.

/* Convert LONGCHAR from GetJsonText() to CHARACTER for MESSAGE */
cJson = STRING(ja:GetJsonText()).

MESSAGE cJson SKIP "Length =" ja:Length VIEW-AS ALERT-BOX.
/* Result: ["A"], Length = 1 */

The following example shows how to use Length to extend the array with null values.

/* Set Length larger -> extends with null values */
USING Progress.Json.ObjectModel.* FROM PROPATH.
VAR JsonArray ja.
VAR CHARACTER cJson.

ja = NEW JsonArray().
ja:Add("A").

ja:Length = 3.

/* Convert LONGCHAR from GetJsonText() to CHARACTER for MESSAGE */
cJson = STRING(ja:GetJsonText()).

MESSAGE cJson SKIP "Length =" ja:Length VIEW-AS ALERT-BOX.
/* Result: ["A",null,null], Length = 3 */

The following example shows a common loop pattern where Length controls iteration across all array elements.

USING Progress.Json.ObjectModel.* FROM PROPATH.
VAR JsonArray ja.
VAR INTEGER i.

ja = NEW JsonArray().
ja:Add("X").
ja:Add("Y").

DO i = 1 TO ja:Length:
  MESSAGE "Item" i "=" ja:GetCharacter(i) VIEW-AS ALERT-BOX.
END.
/* Result: Item 1 = X, Item 2 = Y */