from typing import List
from typing import Any
import json


def retrieve_msg(identifier: str, msg_q) -> List[Any]:
    """Retrieve one msg from msg_q.

    If the msg does not fit identifier, put the msg back in the queue.

    :param identifier:  A unique string to differentiate the recipient of
                        the received message.
    :param msg_q:       A queue to receive msg from rpi_out
    :return: A json-loaded object (or empty list) from the received message.
    """
    msg = msg_q.get()
    msg_list = json.loads(msg)
    # if the received message is not what we want
    if msg_list[0] != identifier:
        msg_q.put(msg)  # put the message back
        msg_list = []  # reset msg_list
    return msg_list