PHP
Chilkat2 PHP
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 PHP Downloads
<?php
use Chilkat2\JsonObject;
$json = new JsonObject();
try {
$json->Load('{"apple": "red","lime": "green","banana": "yellow","broccoli": "green","strawberry": "red"}');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Rename "lime" to "lemon".
$json->Rename('lime', 'lemon');
// Change the color to yellow:
$json->SetStringOf('lemon', 'yellow');
// Rename by index. Banana is at index 2 (apple is at index 0)
$json->RenameAt(2, 'bartlett_pear');
// Delete broccoli by name
$json->Delete('broccoli');
// Delete apple by index. Apple is at index 0.
$json->DeleteAt(0);
$json->EmitCompact = false;
echo $json->Emit(), "\n";