Delete (Json function): Difference between revisions
Jump to navigation
Jump to search
Line 16: | Line 16: | ||
<li>If the Json object is neither an array nor an object an InvalidJsonType exception is thrown.</li> | <li>If the Json object is neither an array nor an object an InvalidJsonType exception is thrown.</li> | ||
<li>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.</li> | <li>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.</li> | ||
<li>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 | <li>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 accessed by the [[ItemByNumber (Json function)|ItemByNumber function]] and does not affect the more common case where they are accessed by name.</li> | ||
<li>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.</li> | <li>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.</li> | ||
<li>If a non-numeric string is used in a Delete call on an array, that string would be converted to a zero (as non-numeric strings are always converted to numbers in SOUL) and that 0 would be an invalid index so result in request cancellation.</li> | <li>If a non-numeric string is used in a Delete call on an array, that string would be converted to a zero (as non-numeric strings are always converted to numbers in SOUL) and that 0 would be an invalid index so result in request cancellation.</li> |
Revision as of 03:06, 18 February 2015
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
%number | number |
---|---|
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 accessed 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.
- If a non-numeric string is used in a Delete call on an array, that string would be converted to a zero (as non-numeric strings are always converted to numbers in SOUL) and that 0 would be an invalid index so result in request cancellation.