Reputation: 20882
$data = array(
'validation' => '1',
'username' => 'peter'),
'password' => 'bigpass'
);
I have a JSON array like this. On the receiving end I want to strip out username and then sent it on in JSON format again - eg: only containing validation and passwd.
Is there a way to strip out a JSON element without decoding it? Or do I have to decode it and convert it into an array, then remove the required element and then re-encode it again?
thx
Upvotes: 0
Views: 739
Reputation: 1487
You could use a RegEx matching the to strip the data, but this is way more error prone and less maintainable than decoding and reencoding it.
If you asked because of performance concerns, JSON is designed to be simple to parse and with data this size the performance should be not affected noticeably and maintainability is way more important.
Upvotes: 1
Reputation: 251
What you have is a PHP array. Serverside you can use all PHP array functions. On the receiving end you can use Javascript's delete function:
yourObj = JSONResponseFromServer;
delete yourObj.validation;
Upvotes: 1
Reputation: 11552
No, PHP doesn't much other than encoding and decoding JSON objects.
Upvotes: 1