Fixed the convert to JSON script to be far more robust.