Edit: Figured it out. See next comment
The short version is that I’m getting On Deck shows from the Plex API. I’m then trying to send this list of shows as an array to a MQTT sensor.
This works:
msg.payload.data = {
topic: 'home/media/plex/short_shows',
payload: "{\"count\":3,\"shows\":[{\"title\":\"30 Rock\"}]}"
}
With this, I get a lovely:
This Does Not Work:
const payload = {
count: 3,
shows: [{ title: '30 Rock' }]
};
const payloadStr = JSON.stringify(payload).replace(/"/g,'\\"');
msg.payload.data = {
topic: 'home/media/plex/short_shows',
payload: payloadStr
}
payloadStr
correctly evaluates to: "{\"count\":3,\"shows\":[{\"title\":\"30 Rock\"}]}"
, which is exactly the same as the manually-typed string above.
However, I get this in the dev tools:
and
For the life of me, I can’t figure out why I can manually type the string and it works, yet I can’t dynamically generate it. Am I doing something stupid?