import json


def get_sqldb_dsn(vcap_services):
    """Returns the data source name for IBM SQL DB."""
    parsed = json.loads(vcap_services)
    credentials = parsed["sqldb"][0]["credentials"]
    user = credentials["username"]
    password = credentials["password"]
    host = credentials["hostname"]
    port = credentials["port"]
    dbname = credentials["db"]
    dsn = """DATABASE={};HOSTNAME={};PORT={};UID={};PWD={};""".format(dbname, host, port, user, password)
    return dsn