Rest command with wled

I have defined 2 rest commands to send text to my wled.

rest_command:
    wled_text1:
        url: http://192.168.111.215/json/state
        method: POST
        payload: '{"seg":[{"n": "{{text}}","id":0}]}'
    wled_text2:
        url: http://192.168.111.215/json/state
        method: POST
        payload: '{"seg":[{"n": "{{text}}","id":1}]}'

When I’m trying to use them everything is working…

action: rest_command.wled_text1
data: { 
  text: Welcome to the MATRIX!!!
}

But when I’m trying to send some data from oter devices (weather forecast data for example) it’s not working:

action: rest_command.wled_text1
data: { 
  text: {{ state_attr('weather.forecast_dom','temperature') }}
}

HA says that there is some syntax error…
Can anyone help me with that problem?

That is neither JSON nor YAML.
Where are you executing this?

Hi in HA home assistant developer tools action

action: rest_command.wled_text1
data:
 text: |-
  {{state_attr('weather.forecast_dom','temperature')}}

worked…
can You explain me why using |- after text helped?

Because templates need to be between quotes, always, and | (or >) does the equivalent.