Write JSON or YAML depending on the file extension.

def write_json_or_yaml(file_path, content):
    """ Write JSON or YAML depending on the file extension. """
    with codecs.open(file_path, "w", "utf-8") as f:
        f.write(get_json_or_yaml(file_path, content))