* resolves #447, add optional file arg to json output arg * write_string_to_file: add type hints, improve error handling