def get_layout_as_dict(layout):
    """
        Take a dict or string and return a dict if the data is json-encoded.
        The string will json parsed to check for json validity. In order to deal
        with strings which have been json encoded multiple times, keep json decoding
        until a dict is retrieved or until a non-json structure is identified.
    """

    if isinstance(layout, dict):
        return layout

    if(isinstance(layout, six.string_types)):
        try:
            return get_layout_as_dict(json.loads(layout))
        except:
            return layout