JsonObjectRemove ( json,key$ )
Parameters
|
json - JSON object handle to modify key$ - property name to remove, exact and case-sensitive |
Description
|
Removes an object property and returns whether it existed. Use it to strip fields from a document before saving - a debug flag left over from testing, a deprecated setting during a save-format migration, a per-session value that should never hit disk. The return value makes it a test-and-remove in one call: true means the key was found and removed, false means there was nothing to remove. Neither case is an error, so calling it "just in case" is fine. Removal shifts nothing else out of order - the remaining keys keep their insertion order. But note the round trip: if you remove a key and later set it again with JsonObjectSet, it re-enters at the end of the order, not at its old position. Copies of the removed value fetched earlier with JsonObjectGet stay valid - they are independent. Keys are strict UTF-8 and case-sensitive; calling JsonObjectRemove on a non-object is a programming error. For the full rules, see the Application Data language reference. Requires Extended mode. See also: JsonObjectSet, JsonObjectClear, JsonObjectHas, JsonArrayRemove, CreateJsonObject. |
Example
; JsonObjectRemove Example ; ------------------------ ; Requires Extended mode. q$=Chr(34) ; Double-quote character, for building JSON text ; A save-game with a debug field left over from testing save=ParseJson("{"+q+"player"+q+":"+q+"Aria"+q+","+q+"cheats"+q+":true,"+q+"gold"+q+":1250}") Print "Before: "+JsonStringify(save,0) Print "" ; JsonObjectRemove deletes a property and reports whether it existed existed=JsonObjectRemove(save,"cheats") Print "Remove 'cheats' - existed = "+existed ; Removing it again finds nothing and returns false existed=JsonObjectRemove(save,"cheats") Print "Remove again - existed = "+existed Print "" Print "After: "+JsonStringify(save,0) FreeJson save Print "" Print "Press any key to close the example" WaitKey End
Index