Updating An Existing JSON file

Hello,

I have a JSON file message_list.json that stores some messages and a time stamp.

{
    "messages": [
        {
            "time_stamp": "01:00",
            "message": "This is message 1"
        },
        {
            "time_stamp": "02:00",
            "message": "This is message 2"
        },
        {
            "time_stamp": "03:00",
            "message": "This is message 3"
        }
    ]
}

I am extracting this to a sensor in HAOS using jq.

> sensor:
>   - platform: command_line
>     name: JQ Message List
>     command: "jq . logs/message_list.json"
>     value_template: "{{ value_json.messages[0].message }}"
>     json_attributes:
>       - messages
>     scan_interval: 15 #seconds
friendly_name: JQ Message List
messages:
  - time_stamp: '01:00'
    message: This is message 1
  - time_stamp: '02:00'
    message: This is message 2
  - time_stamp: '03:00'
    message: This is message 3

I would like to update the JSON file with new entries. I have tried by using the notify command_line service but it breaks the JSON because it just appends the line at the end.

> notify:
>   - platform: command_line
>     name: Log Notification
>     command: "sed 's/^!//' >> logs/message_list.json"
> service: notify.log_notification
> data: 
>   message: "{"time_stamp", "04:00", "message": "This is message 4"}"

Output:

{
    "messages": [
        {
            "time_stamp": "01:00",
            "message": "This is message 1"
        },
        {
            "time_stamp": "02:00",
            "message": "This is message 2"
        },
        {
            "time_stamp": "03:00",
            "message": "This is message 3"
        }
    ]
}{"time_stamp", "04:00", "message": "This is message 4"}

Is there a way to add lines to this file and still maintain the JSON structure?