Sample code for 30+ languages & platforms
AutoIt

JSON: Renaming and Deleting Members

See more JSON Examples

Demonstrates renaming and deleting members. This example uses the following JSON document:
{
   "apple": "red",
   "lime": "green",
   "banana": "yellow",
   "broccoli": "green",
   "strawberry": "red"
}

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oJson = ObjCreate("Chilkat.JsonObject")

$bSuccess = $oJson.Load("{""apple"": ""red"",""lime"": ""green"",""banana"": ""yellow"",""broccoli"": ""green"",""strawberry"": ""red""}")
If ($bSuccess <> True) Then
    ConsoleWrite($oJson.LastErrorText & @CRLF)
    Exit
EndIf

; Rename "lime" to "lemon".
$bSuccess = $oJson.Rename("lime","lemon")
; Change the color to yellow:
$bSuccess = $oJson.SetStringOf("lemon","yellow")

; Rename by index.  Banana is at index 2 (apple is at index 0)
$bSuccess = $oJson.RenameAt(2,"bartlett_pear")

; Delete broccoli by name
$bSuccess = $oJson.Delete("broccoli")

; Delete apple by index.  Apple is at index 0.
$bSuccess = $oJson.DeleteAt(0)

$oJson.EmitCompact = False
ConsoleWrite($oJson.Emit() & @CRLF)