import socket
import json


def get_json_data(stats_sock):
    """Returns uwsgi stats data as dict from the socket file."""
    data_dict = {}
    data = ""
    try:
        with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
            s.connect(stats_sock)
            while True:
                d = s.recv(4096)
                if len(d) < 1:
                    break
                data += d.decode("utf8", "ignore")
            s.close()
        data_dict = json.loads(data)
    except Exception as e:
        print(e)
        pass
    return data_dict