How to build a JSON in a defined format

Hi,

I stuck in a pretty basic propblem. Could someone give me a hint please.

My challenage:

I need to compile a MQTT Message with a fixed format. The Value I want to send I have, but I do not understand how to build exactly this JSON format to send it afterwards as MQTT out.

Target Format:
{
"pv": {
"power": 0.0,
"L1": {
"power": 0.0
}
}
}

0.0 is the actual measurement value I want to get into the message.

How can I do this?

I tried the template function but receive always an error.

that's my node.
[{"id":"b2aab1de18a3670f","type":"template","z":"06d63c099a670eab","name":"Build JSON","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n \"pv\": {\n \"power\": payload,\n \"L1\": {\n \"power\": payload\n }\n }\n}","output":"json","x":1890,"y":460,"wires":[["03267eaa74855d0d"]]},{"id":"f35c88ebfcbe16d7","type":"inject","z":"06d63c099a670eab","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"144","payloadType":"num","x":1650,"y":460,"wires":[["b2aab1de18a3670f"]]},{"id":"03267eaa74855d0d","type":"debug","z":"06d63c099a670eab","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2100,"y":460,"wires":[]}] type or paste code here

I know this might be a very basic question; I would be happy if someone can give me a hint.

Did you read the built in help on the sidebar (to the right)?

I'm certain it shows you how to add variable using {{mustache}} syntax

Thanks, "{{ }}" was the hint I needed.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.