Fixed filename handling when writing json.