Object vs strings - extract a value from a split

You need to understand the differnece (and advantage) of using objects and properties in node-red (and JavaScript in general).

For example, if you have an object, there is ZERO need to split strings etc.

JSON stands for JavaScript Object Notation - meaning it is a string representation of a JS object - which is useful for transmitting between devices and across the internet (they all do strings right!). That is why JSON is so popular - because it is REALLY EASILY convert to/from object/string.

So, when your data is a string, you have to split and mess about with it. Worse still if you want to change a value.


So the simple way to deal with JSON strings is to use a JSON node to convert the JSON string to a JS object. Or in you case, switch the inject to JSON mode ...

image

--- ↑ change to ↓ ---

image


then it is childs play grabing (or changing) any of the values you want...


I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

3 Likes