code: def convert_nexson_format(blob,
                            out_nexson_format,
                            current_format=None,
                            remove_old_structs=True,
                            pristine_if_invalid=False,
                            sort_arbitrary=False):
      if not current_format:
          current_format = detect_nexson_version(blob)
      out_nexson_format = resolve_nexson_format(out_nexson_format)
      if current_format == out_nexson_format:
          if sort_arbitrary:
              sort_arbitrarily_ordered_nexson(blob)
          return blob
      two2zero = _is_by_id_hbf(out_nexson_format) and _is_badgerfish_version(current_format)
      zero2two = _is_by_id_hbf(current_format) and _is_badgerfish_version(out_nexson_format)
      if two2zero or zero2two:
          blob = convert_nexson_format(blob,
                                       DIRECT_HONEY_BADGERFISH,
                                       current_format=current_format,
                                       remove_old_structs=remove_old_structs,
                                       pristine_if_invalid=pristine_if_invalid)
          current_format = DIRECT_HONEY_BADGERFISH
      ccdict = {'output_format': out_nexson_format,
                'input_format': current_format,
                'remove_old_structs': remove_old_structs,
                'pristine_if_invalid': pristine_if_invalid}
      ccfg = ConversionConfig(ccdict)
      if _is_badgerfish_version(current_format):
          converter = Badgerfish2DirectNexson(ccfg)
      elif _is_badgerfish_version(out_nexson_format):
          assert _is_direct_hbf(current_format)
          converter = Direct2BadgerfishNexson(ccfg)
      elif _is_direct_hbf(current_format) and (out_nexson_format == BY_ID_HONEY_BADGERFISH):
          converter = Direct2OptimalNexson(ccfg)
      elif _is_direct_hbf(out_nexson_format) and (current_format == BY_ID_HONEY_BADGERFISH):
          converter = Optimal2DirectNexson(ccfg)
      else:
          raise NotImplementedError('Conversion from {i} to {o}'.format(i=current_format, o=out_nexson_format))
      blob = converter.convert(blob)
      if sort_arbitrary:
          sort_arbitrarily_ordered_nexson(blob)
      return blob