# Drag&Drop handling of JSON string that isn't an array of nodes

**URL:** https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206
**Category:** Core Development
**Created:** [17 November 2024 15:36 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206 "2024-11-17T15:36:48Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [17 November 2024 15:36 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/1 "2024-11-17T15:36:48Z")

</div>

Hi There,

When I drag and drop the string "[0]" (with or without the quotes) onto Node-RED workspace, I get this error:

![Screenshot 2024-11-17 at 16.17.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3b1a32912b0e29c3aba9558b8ba75539999b076.png)

(or `e.type is undefined` depending on the minification of the .js.)

This was using NR 4.0.5.

What is happening is that the drag&drop behaviour _assumes_ that if the content can be parsed as valid JSON then it _must_ be an array of nodes.

I as a user have no idea why that is happening nor does the error message help me, all I did was drag JSON content onto the workspace.

The cause of the error is this [line](https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node_modules/%40node-red/editor-client/src/js/nodes.js#L1917) in RED.node.import and this [code](https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node_modules/%40node-red/editor-client/src/js/ui/view.js#L5935-L5937) is displaying the error message.

It might be better to ignore that error and not display it to the user. Drops that aren't handled are also silently ignored, i.e., the user won't necessarily expect feedback to be generated from their drop.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [17 November 2024 15:49 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/2 "2024-11-17T15:49:27Z")

</div>

Sure the console could display the whole error instead of just the stack trace.

But, your case is related to your drag and drop plugin, the core uses drag and drop to import **flows**. It is not supposed to support anything else (on the workspace).

The common error when importing is a malformed JSON flow and there the error is notified via a more understandable message by the user.

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [17 November 2024 16:09 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/3 "2024-11-17T16:09:02Z")

</div>

> [@GogoVega](#):
>
> But, your case is related to your drag and drop plugin, the core uses drag and drop to import **flows**. It is not supposed to support anything else (on the workspace).

But images can also be drag&dropped into the editor. So flows aren't the only thing being dragged onto the workspace.

> [@GogoVega](#):
>
> The common error when importing is a malformed JSON

I don't get an error when dragging malformed JSON, I get nothing. No message, no flow, just silence. That's also unexpected behaviour.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [17 November 2024 16:09 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/4 "2024-11-17T16:09:08Z")

</div>

Perhaps a PR to enhance the error message might be useful?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [17 November 2024 16:20 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/5 "2024-11-17T16:20:58Z")

</div>

Best place to report a bug is the GitHub issue tracker.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [17 November 2024 16:21 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/6 "2024-11-17T16:21:53Z")

</div>

> [@gregorius](#):
>
> But images can also be drag&dropped into the editor. So flows aren't the only thing being dragged onto the workspace.

Editor is not the workspace.

> [@gregorius](#):
>
> I don't get an error when dragging malformed JSON, I get nothing. No message, no flow, just silence. That's also unexpected behaviour.

Yeah strange, will investigate later. I have the error in the console only.

> [@TotallyInformation](#):
>
> Perhaps a PR to enhance the error message might be useful?

Depends on what the core is supposed to handle.

---

<div class="post-metadata">

### Author: ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)
#### Post date: [17 November 2024 16:31 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/7 "2024-11-17T16:31:33Z")

</div>

> [@knolleary](#):
>
> report a bug is the GitHub issue

> <https://github.com/node-red/node-red/issues/4962>
>
> \### Current Behavior
> 
> When I drag and drop the string "\[0\]" (with or without the… quotes) onto Node-RED workspace, I get this error:
> 
> !\[img\](https://cdn.openmindmap.org/content/1731860827824\_Screenshot\_2024-11-17\_at\_16.17.43.png)
> 
> (or e.type is undefined depending on the minification of the .js.)
> 
> What is happening is that the drag&drop behaviour assumes that if the content can be parsed as valid JSON then it must be an array of nodes.
> 
> I as a user have no idea why that is happening nor does the error message help me, all I did was drag JSON content onto the workspace.
> 
> The cause of the error is this \[line\](https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node\_modules/%40node-red/editor-client/src/js/nodes.js#L1917) in RED.node.import and this \[code\](https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node\_modules/%40node-red/editor-client/src/js/ui/view.js#L5935-L5937) is displaying the error message.
> 
> It might be better to ignore that error and not display it to the user. Drops that aren't handled are also silently ignored, i.e., the user won't necessarily expect feedback to be generated from their drop.
> 
> \### Expected Behavior
> 
> Sensible error message or no error message.
> 
> \### Steps To Reproduce
> 
> Drag "\[0\]" onto the workspace of the editor.
> 
> \### Example flow
> 
> \`\`\`
> paste your flow here
> \`\`\`
> 
> 
> \### Environment
> 
> \- Node-RED version: 4.0.5
> \- Node.js version: 22
> \- npm version: 
> \- Platform/OS: Docker Image 
> \- Browser: Firefox

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 December 2024 16:32 UTC](https://discourse.nodered.org/t/drag-drop-handling-of-json-string-that-isnt-an-array-of-nodes/93206/8 "2024-12-01T16:32:01Z")

</div>

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