How to share code or flow json

To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly.

The easiest way to do that is to click the 'Preformatted Text' button in the toolbar:

image

Then paste in your code or flow json.

On standard US English keyboards, this is on the same key as the ~ character.

```
[{"id":"bbef23cc.4e7f18","type":"inject","x":100, "y": 50, "wires":[[]]}]
```

You can see the quotes remain untouched.

When sharing Flow JSON, add the text flows after the first set of back-ticks:

```flows
[{"id":"bbef23cc.4e7f18","type":"inject","x":100, "y": 50, "wires":[[]]}]
```

This will then get rendered as a flow:

[{"id":"bbef23cc.4e7f18","type":"inject","x":100, "y": 50, "wires":[[]]}]

For code from a Function node, first without the backticks:

msg.payload = "Hello There";
return msg;

And again, with the backticks:

msg.payload = "Hello There";
return msg;

The added syntax highlighting also makes it much easier to read.

This should be used for any code samples, such as flow JSON, JavaScript, html or XML samples.

21 Likes

Also, larger flows can now be saved as a txt or json file and uploaded directly to the post.

Paul

7 Likes

Complete beginner here, but I have ended up with tons of listings of "Home Assistant" as the server for Node-Red to connect to. Mauricio Bonani @mbonani wrote a JSON scrubber that I now use every time I import a flow in a post https://bonani.tech/a-good-practice-when-sharing-node-red-flows-with-home-assistant-nodes/, with the actual scrubber at https://zachowj.github.io/node-red-contrib-home-assistant-websocket/scrubber/

5 Likes

Thank you @euromem. Just a small correction, the scrubber was written by Jason Zachow, not by me.

3 Likes

Just to note the advice of pasting in your code then selecting then clicking preformatted text doesn't seem to work reliably - apparently it's better to click the button then paste your text into the newly created 'space'.

1 Like

@dclear thanks - have updated the guidance to match