import json


def decode_json(data):
    """
    The passbolt API returns legacy strings or JSON objects.
    Try to decode JSON, and if invalid return string.
    """
    try:
        data = json.loads(data)
    except json.decoder.JSONDecodeError:
        return data
    return data["password"]