Function EN Version 12.11

@JsonRemove

Json

Syntax

@JsonRemove(HJSON;KEY);
@JsonRemove(HJSON;INDEX);

Description

This @Function removes a value from an existing JSON object or JSON array.

For a JSON object, the second parameter must be a TEXT KEY. The value associated with the specified key is removed from the object.
For a JSON array, the second parameter must be a numeric FN INDEX. JSON arrays use zero-based indexing, therefore the first element has index 0.

After an element is removed from a JSON array, all following elements are shifted forward accordingly.
As return value, the @Function returns @ERROR on failure; otherwise, it returns TRUE.

VSPECHJSON HJSON:
Handle of the JSON object or JSON array from which a value is to be removed.
HJSON must contain a valid VSPECHJSON (HJS) handle.

TEXT KEY:
Key of the value to be removed from a JSON object.

FN INDEX:
Index of the element to be removed from a JSON array; indexing starts at 0.
The parameter may be specified as NUMBER or FLOAT.

Example: @JsonRemove(HJSON;KEY);
HJSON:=@JsonParse("{\"Name\":\"Max Mustermann\",\"Age\":42,\"Active\":true}");
@JsonRemove(HJSON;"Age");
JSONTEXT:=@JsonSerialize(HJSON;"A");
@JsonRelease(HJSON);

The resulting JSON structure is:
{"Name":"Max Mustermann","Active":true}

If the specified key does not exist, the function returns @ERROR.

Example: @JsonRemove(HJSON;INDEX);
HJSON:=@JsonParse("[\"A\",\"B\",\"C\"]");
@JsonRemove(HJSON;1);
JSONTEXT:=@JsonSerialize(HJSON;"A");
@JsonRelease(HJSON);

The resulting JSON structure is:
["A","C"]

Since the element at index 1 was removed, the element previously located at index 2 is shifted to index 1.
An invalid index or an index outside the array results in @ERROR.

Note : This text was machine-translated and may contain inaccuracies.