When developing with backend technologies like PHP, a time comes when you need to use and manipulate JSON objects. One of such manipulations is removing or deleting a JSON key.
There are several ways to do this, however, I find the below method preferable.
1 |
unset($json["key"]); |
Note that for this method to work, you need to pass a true parameter to the second argument of the json_decode() method. See the below sample:
1 2 |
$json = json_decode($json , true); unset($json["key"]); |
The second parameter simply tells the method to return an associative array instead of an object.
Hope this helps.
If you have any questions, feel free to ask them in the comment box below. 🙂