def remove_objects(code, count=1):
 replacements = {}
 br = bracket_split(code, ['{}', '[]'])
 res = ''
 last = ''
 for e in br:
  if (e[0] == '{'):
   (n, temp_rep, cand_count) = remove_objects(e[1:(-1)], count)
   if is_object(n, last):
    res += (' ' + (OBJECT_LVAL % count))
    replacements[(OBJECT_LVAL % count)] = e
    count += 1
   else:
    res += ('{%s}' % n)
    count = cand_count
    replacements.update(temp_rep)
  elif (e[0] == '['):
   if is_array(last):
    res += e
   else:
    (n, rep, count) = remove_objects(e[1:(-1)], count)
    res += ('[%s]' % n)
    replacements.update(rep)
  else:
   res += e
  last = e
 return (res, replacements, count)

def remove_objects ( code , count = 1 ) : replacements = { } br = bracket_split ( code , [ '{}' , '[]' ] ) res = '' last = '' for e in br : if ( e [ 0 ] == '{' ) : ( n , temp_rep , cand_count ) = remove_objects ( e [ 1 : ( - 1 ) ] , count ) if is_object ( n , last ) : res += ( ' ' + ( OBJECT_LVAL % count ) ) replacements [ ( OBJECT_LVAL % count ) ] = e count += 1 else : res += ( '{%s}' % n ) count = cand_count replacements . update ( temp_rep ) elif ( e [ 0 ] == '[' ) : if is_array ( last ) : res += e else : ( n , rep , count ) = remove_objects ( e [ 1 : ( - 1 ) ] , count ) res += ( '[%s]' % n ) replacements . update ( rep ) else : res += e last = e return ( res , replacements , count )
this function replaces objects with objects_lvals .