Multiple states send in one MQTT json string

Hi there

I have 8 switches and I need to send the command of each switch (1/0) in json like this by MQTT. In my example it goes Switch1, Switch2, Switch3…Switch8. All separated by a comma and space

I know how to send correctly the switch command for one switch, but how for 8 together? Need to send on every time one of the 8 switches is operated and periodically.

State ON ="1"
State OFF ="0"

{"data": [0, 1, 0, 0, 0, 1, 0, 1] }; 

I’m thinking something like [Switch1.state, Switch2.state, … Switch8.state]

Thanks for any directions you can offer.

I would put into a script.
some like this

Switch_1to8:
  alias: Send all 8 state in on go
  sequence:
  - action: mqtt.publish
    data:
      topic: home/8switchonoff
      payload: '
          {%-set s1 = states.switch.charger.state -%}
          {%-set s2 = states.switch.charger.state -%}
          {%-set s3 = states.switch.charger.state -%}
          {%-set s4 = states.switch.charger.state -%}
          {%-set s5 = states.switch.charger.state -%}
          {%-set s6 = states.switch.charger.state -%}
          {%-set s7 = states.switch.charger.state -%}
          {%-set s8 = states.switch.charger.state -%}
          {%- set payload = "{data: [" + s1 +" ,"+ s2 +" ,"+ s1 +" ,"+ s1 +" ,"+ s1 +" ,"+ s1 +" ,"+ s1 +" ,"+ s1 +" ]};" -%}
          {{ payload }}'

then run the script each one of those switches get toggled