Cannot call json request

I’m trying to call a http_request.post within an ESPhome script that should address a JSON key into the fabulous WLED API. Now with endless attempts I’m stuck, not knowing what to do next.

If I understand the WLED api well (described here), a post request in JSON shall look like, for example:

{"seg":[{"on":[[0,true]]}]}

This example should turn on the first segment (#0) in a LED strip.

When embedding this in the http_request it looks like:

# Setup HTTP request component
http_request:
#  useragent: esphome/device
#  timeout: 10s
    
script:
  id: ondownup
  then:
    - http_request.post:
        url: http://192.168.1.61/json
        headers:
          Content-Type: application/json
        json:
          key: {"seg":[{"on":[[0,true]]}]}
        verify_ssl: false

I am obviously not a crack in this, but hope that someone can give me insight why this won’t go. ESPhome gives the message that this shall be a string (as in within quotes), however, that seems not to work.

I would expect it to be something like this:
{ “seg” : [ {“on”: true } ] }

Dankjewel Sjaak, I see you using different quotes than I do .

you: “ ”
versus me: " "

If I watch the examples on the JSON API page, the quotes that I use are identical from that page. Even copy - paste his code gives compilation errors. With your quotes I can compile my code, though, the result is not jet there. Anyhow, can you let me know how to use these quotes and what is the thing behind. Maybe it brings me further. Noob question probably…

Just use normal quotes…i think the weird quotes are some fancy formatting

that unfortunately doesn’t compile. Have to play further then. Thank you.

I just did a packet capture turning off segment 0 on one of my WLED units and this is what I got:

{"seg":{"id":0,"on":false},"v":true,"time":1612125701}

I’m not sure if the [ ]'s are needed because even WLED’s web interface doesn’t send it when turning on/off the segment from the segments “tab”. I would just try {“seg”:{“id”:0,“on”:true}} as a test - including the segment ID because it is not passing an array/list of segments, just telling it segment 0