Fix JSON replacer function and test scripts.

This function was completely broken, my bad.