Bug Fix for bug#61537 json_encode() incorrectly truncates/discards infor...

...mation

json_encode() will now always return bool(false) if an error is present

I'm resubmitting this since the previous patch was reverted. This was originally intended as a temporary workaround but someone has suggested it be submitted in light of the revert to close the bug report. Let me know if any changes need to go through (I'm submitting this PR for master).