def jsonify(tokens):
 for token in tokens:
  if (token.type == u'FUNCTION'):
   (yield (token.type, token.function_name, list(jsonify(token.content))))
  elif token.is_container:
   (yield (token.type, list(jsonify(token.content))))
  else:
   (yield (token.type, token.value))

def jsonify ( tokens ) : for token in tokens : if ( token . type == u'FUNCTION' ) : ( yield ( token . type , token . function_name , list ( jsonify ( token . content ) ) ) ) elif token . is_container : ( yield ( token . type , list ( jsonify ( token . content ) ) ) ) else : ( yield ( token . type , token . value ) )
format json output .