docstr: Convert HOCON input into a HOCON output
  
  :return: JSON string representation
  :type return: basestring
docstr_tok: ["Convert","HOCON","input","into","a","HOCON","output",":","return",":","JSON","string","representation",":","type","return",":","basestring"]
code: def to_hocon(cls, config, compact=False, indent=2, level=0):
      """Convert HOCON input into a HOCON output
  
      :return: JSON string representation
      :type return: basestring
      """
      lines = ""
      if isinstance(config, ConfigTree):
          if len(config) == 0:
              lines += "{}"
          else:
              if level > 0:  # don't display { at root level
                  lines += "{\n"
              bet_lines = []
  
              for key, item in config.items():
                  if compact:
                      full_key = key
                      while (
                          isinstance(item, ConfigTree)
                          and len(item) == 1
                      ):
                          key, item = next(iter(item.items()))
                          full_key += "." + key
                  else:
                      full_key = key
  
                  if isinstance(full_key, float) or (
                      isinstance(full_key, (basestring, unicode))
                      and cls._number_re_matcher.match(full_key)
                  ):
                      # if key can be casted to float, and it is a string, make sure we quote it
                      full_key = '"{}"'.format(full_key)
  
                  bet_line = "{indent}{key}{assign_sign} ".format(
                      indent="".rjust(level * indent, " "),
                      key=full_key,
                      assign_sign=""
                      if isinstance(item, dict)
                      else " =",
                  )
                  value_line = cls.to_hocon(
                      item, compact, indent, level + 1
                  )
                  if isinstance(item, (list, tuple)):
                      bet_lines.append(
                          cls._auto_indent(bet_line, value_line)
                      )
                  else:
                      bet_lines.append(bet_line + value_line)
              lines += "\n".join(bet_lines)
  
              if level > 0:  # don't display { at root level
                  lines += "\n{indent}}}".format(
                      indent="".rjust((level - 1) * indent, " ")
                  )
      elif isinstance(config, (list, tuple)):
          if len(config) == 0:
              lines += "[]"
          else:
              # lines += '[\n'
              lines += "["
              bet_lines = []
              base_len = len(lines)
              skip_comma = False
              for i, item in enumerate(config):
                  if 0 < i and not skip_comma:
                      # if not isinstance(item, (str, int, float)):
                      #     lines += ',\n{indent}'.format(indent=''.rjust(level * indent, ' '))
                      # else:
                      #     lines += ', '
                      lines += ", "
  
                  skip_comma = False
                  new_line = cls.to_hocon(
                      item, compact, indent, level + 1
                  )
                  lines += new_line
                  if "\n" in new_line or len(lines) - base_len > 80:
                      if i < len(config) - 1:
                          lines += ",\n{indent}".format(
                              indent="".rjust(level * indent, " ")
                          )
                      base_len = len(lines)
                      skip_comma = True
                  # bet_lines.append('{value}'.format(value=cls.to_hocon(item, compact, indent, level + 1)))
  
              # lines += '\n'.join(bet_lines)
              # lines += ', '.join(bet_lines)
  
              # lines += '\n{indent}]'.format(indent=''.rjust((level - 1) * indent, ' '))
              lines += "]"
      elif isinstance(config, basestring):
          if "\n" in config and len(config) > 1:
              lines = '"""{value}"""'.format(value=config)  # multilines
          else:
              lines = '"{value}"'.format(
                  value=cls.__escape_string(config)
              )
      elif isinstance(config, ConfigValues):
          lines = "".join(
              cls.to_hocon(o, compact, indent, level)
              for o in config.tokens
          )
      elif isinstance(config, ConfigSubstitution):
          lines = "${"
          if config.optional:
              lines += "?"
          lines += config.variable + "}" + config.ws
      elif isinstance(config, ConfigQuotedString):
          if "\n" in config.value and len(config.value) > 1:
              lines = '"""{value}"""'.format(
                  value=config.value
              )  # multilines
          else:
              lines = '"{value}"'.format(
                  value=cls.__escape_string(config.value)
              )
      elif config is None or isinstance(config, NoneValue):
          lines = "null"
      elif config is True:
          lines = "true"
      elif config is False:
          lines = "false"
      else:
          lines = str(config)
      return lines
  
file_path: clearml/clearml/utilities/pyhocon/converter.py
imports: import json
  import re
  import sys
  from .None import ConfigFactory
  from .config_tree import ConfigQuotedString
  from .config_tree import ConfigSubstitution
  from .config_tree import ConfigTree
  from .config_tree import ConfigValues
  from .config_tree import NoneValue
label_desc: Use image node_id 3 for calling the HOCONConverter obj's underlying member method code with example usage: obj.to_hocon(cls, config, compact, indent, level) and returns: lines