Using regex in python call to API to clean up return
Question: The following Python Script:

    
    
    def lookup(guildname):
        try:
            guildname = gw2api.get_guild_details(guildid)
            return guildname
        except:
            return''
    

Returns results that look like this: (each are single line)

    
    
    {u'emblem': {u'foreground_secondary_color_id': 443, u'foreground_primary_color_id': 584, u'foreground_id': 107, u'background_id': 27, u'flags': [], u'background_color_id': 11}, u'guild_id': u'4FAEB34C-BA01-49C8-AD19-C651D69F9981', u'tag': u'RAWK', u'guild_name': u'Ready And Willing Knights'}
    {u'emblem': {u'foreground_secondary_color_id': 443, u'foreground_primary_color_id': 11, u'foreground_id': 144, u'background_id': 22, u'flags': [u'FlipBackgroundHorizontal'], u'background_color_id': 4}, u'guild_id': u'DDE74A26-FC28-4514-926D-9BB590E6BDD2', u'tag': u'AI', u'guild_name': u'Alchemy Incorporated'}
    {u'emblem': {u'foreground_secondary_color_id': 64, u'foreground_primary_color_id': 146, u'foreground_id': 148, u'background_id': 21, u'flags': [], u'background_color_id': 617}, u'guild_id': u'190E573E-8970-440E-8EA1-653098296EDB', u'tag': u'RoMS', u'guild_name': u'Roses Of The Moonlight Sigil'}
    

Using Regex I think I can get the guild name

    
    
    ([A-Z0-9a-z-]*\b [A-Z0-9a-z-]*)
    

But how do I apply that to the above python script? It needs to return just
the unique guild name like `Roses Of The Moonlight Sigil` and `Alchemy
Incorporated` instead of that huge big block. Not really sure if I have the
right expression

Edit with proper function:

    
    
    import json, gw2api
    
    getguild = gw2api.get_servers()
    guildapi = json.dumps(getguild)
    apiresult = json.loads(guildapi)
    
    print apiresult['name']
    


Answer: Use [`json.loads()`](http://docs.python.org/2/library/json.html#json.loads),
then access it as a normal dictionary. Regex is not needed:

    
    
    import json
    ...
    return json.loads(guildname)
    
    thedict = the_one_returned
    print thedict['guild_name']
    # Prints Ready And Willing Knights
    

