$json considered harmful?

When you create a new node3, using data from the previous node1, it’s referenced as $json.foo, but as soon as you add a new node2 between node1 and node3, the node3’s $json.foo becomes invalid (the new node2 is not yielding a foo property).

I think all data references should be absolute references ( $input['node1'].item.json.foo ).
Or maybe this could be a configuration option? “When dragging and dropping a key from the schema, create [absolute | relative] references”

Hey @Martin_Sarsale1 hope all is well, welcome to the community.

I think when you are building the flow, you rarely don’t know where you are taking the data from - last node or one of the nodes before that. Being able to reference the last node’s value with just $json.value is a good convenience, makes expressions easier to read and most importantly doesn’t rely on the node’s name which can be changed at any time.

Think about it, you create a node with the default name, use it in 25 other nodes by name and being a perfectionist you will want to prettify the flow when done - you rename the node to something actually useful and there you have it - now you need to go and change it in 25 other places.

In my opinion, having it both ways is beneficial and makes total sense.

When you rename a node, all the explicit references to that node are automatically updated.

Ha, thank you I didn’t know that.

The rest stands true though - the convenience of not having to type the name of the node, shorter and easier to read look, and honestly this syntax is all most small flows need anyway.

It also makes it easier to re-use parts of the workflow (in your own workflows or when shared) - relying on previous node’s data is a common practice and used in most neighbouring node communications.

@Martin_Sarsale1 is absolutely correct! Ideally it should work like that:

Without it, folks spend TONS of time fixing the workflows, replacing relative links to absolute

Disagree. Want to re-use workflows? Create a sub-workflow, this is supposed to be the way to go, not the copy&pasting.

The “convenience of not having to type the name of the node“ is there just because currently the n8n’s UI can’t produce an absolute link when you dragNdrop a value from the left side. Hence the suggestion to add a “hold shift“ option to produce an absolute link,

Sorry, but this is a bad idea. Had the same conversation on the discord.

Sorry to say this, but the fact you want this shows you do not understand how n8n works. A node runs for its inputs. So working with the data coming in is the way to go. Of course there are moments you don’t want this but in most cases using $json is the way to go.

1 Like

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