import struct
import json


def get_length_encoded_json(stream):
    """
    Reads a JSON string from a bytestream, producing a dictionary.

    :raises EOFError: If the stream isn't long enough.
    """
    length_bytes = stream.read(2)
    if len(length_bytes) != 2:
        raise EOFError

    length = struct.unpack('H', length_bytes)[0]
    json_bytes = stream.read(length)
    if len(json_bytes) != length:
        raise EOFError

    json_str = json_bytes.decode('utf-8')
    return json.loads(json_str)