@shiva something like this?
$clients = (array)json_decode(file_get_contents(storage_path('/Clients/clients.json')));
$result = [];
foreach($client as $key => $value)
{
$key = ($key === $old_code) ? $new_code : $key;
$result[$key] = $value;
};
// do something with $result
a note, I've renamed your $json variable as, at that point, its a normal array not json object.
if you want to do multiple, make an array of your old and new values and do the following
$swaps[
'CL001' => 'PR001',
'CL002' => 'PR002'
];
$clients = (array)json_decode(file_get_contents(storage_path('/Clients/clients.json')));
$result = [];
foreach($clients as $key => $value)
{
$key = isset($swaps[$key]) ? $swaps[$key] : $key;
$result[$key] = $value;
};
// do something with $result