Preserving whitespace and some cleanup

Hi

I added preservation of whitespace for the JSON files, and did some clean up with naming and usage of single and double quotes. Also omits new line if original source file doesn't end with a new line. 

The code is originally from [the mversion module](https://github.com/mikaelbr/mversion) and the credit belongs to [k88hudson](https://github.com/mikaelbr/mversion/pull/9) and [garryyao](https://github.com/mikaelbr/mversion/pull/7).