Fixed the resetting of the json file on removal failures

Closes #3329
Merge pull request #3330 from stof/patch-1

Fixed the resetting of the json file on removal failures