Delete (Json function)

From m204wiki
Revision as of 22:17, 17 February 2015 by Alex (talk | contribs) (→‎Syntax terms)
Jump to navigation Jump to search

Delete a JSON object/array item value (Json class)

[Introduced in Model 204 7.6]

This function deletes an item from a Json array or object.

Syntax

[%number =] json:Delete( index) Throws InvalidJsonType

Syntax terms

%numbernumber
Json Json object, which must be either an array or obvject.
index A value to be used as the index of the item to be deleted. If the Json object is an array this value is treated as a number. If the Json object is an object, this value is treated as a (unicode) string.

Usage notes

  • If the json object is neither an array nor an object an InvalidJsonType exception is thrown.
  • Attempting to delete an item number not in an array results in request cancellation whereas deleting an object name not in the object is simply a no-op.
  • Deleting an item from the middle of an array or object simply shifts subsequent items down. This means that subsequent items after a delete are accessed by a number one less than before. This only affects objects (as opposed to arrays) when their items are access by the ItemByNumber function and does not affect the more common case where they are accessed by name.
  • Deleting an item from an array or object does not delete that object unless the only reference to the object is the one being deleted.

Examples

See also