import json


def send(s, req):
    """Sends a JSON formatted request and returns the response.

    This will wait/block until a response is received or timeout occurs

    Args:
        s (socket): socket to send request over
        req (dict): request to convert to json and send over socket

    Returns:
        dict: JSON formatted response
    """
    msg = json.dumps(req)
    s.sendall(b"%s\n" % msg.encode())

    r = bytearray()
    while b"\n" not in r:
        r.extend(s.recv(1024))

    result = json.loads(r.decode())
    return result