# Bug in Code node

**URL:** <https://community.n8n.io/t/bug-in-code-node/23215>\
**Category:** Questions\
**Tags:** code\
**Created:** [February 19, 2023, 3:14pm UTC](https://community.n8n.io/t/bug-in-code-node/23215 "2023-02-19T15:14:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrey-42](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shrey-42/32/3437_2.png) [@shrey-42](https://community.n8n.io/u/shrey-42)\
**Post date:** [February 19, 2023, 3:14pm UTC](https://community.n8n.io/t/bug-in-code-node/23215/1 "2023-02-19T15:14:20Z")

</div>

## Describe the issue/error/question

Code node is giving the error `ERROR: A 'json' property isn't an object` when there’s no reason for it to. It can also be seen in the console that the json data seems to be properly structured.

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/e/d/ed14f0be558beaa3b09b14bccda275616414c22b.png)

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/1/b/1b528333e2e0e75d8b6c5f4e5cb7524de55d89ce.png)

## Information on your n8n setup

- **n8n version:** 0.216.0
- **Database you’re using (default: SQLite):** Postgres
- **Running n8n with the execution process [own(default), main]:** default
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]:** Docker

---

<div class="post-metadata">

**Author:** ![shrey-42](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shrey-42/32/3437_2.png) [@shrey-42](https://community.n8n.io/u/shrey-42)\
**Post date:** [February 19, 2023, 4:00pm UTC](https://community.n8n.io/t/bug-in-code-node/23215/2 "2023-02-19T16:00:26Z")

</div>

Update:

Upon further investigation, the input data’s structure (Array in the root level) in this case, seems to be responsible for this scenario (in conjunction with the Code node).

* * *
Incoming data's schema:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/4/e/4ecad1990c7f4c5cc765c070e65116b7a5372c78.png)

* * *

When i try the same thing with the old Function node, it works fine:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/a/8/a8b9cd340fcb7157b9e6b854fb26c1aa9f50a785.png)

* * *

This should work fine in the Code node as well, right ?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [February 20, 2023, 8:48am UTC](https://community.n8n.io/t/bug-in-code-node/23215/3 "2023-02-20T08:48:22Z")

</div>

Hi @shrey-42, I am sorry you’re having trouble. I just tried reproducing this on my end, but the Code node in the below example workflow runs fine for me on n8n@0.216.0:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/c/e/cecbadd532b3006cd3739e7dfcc46f866c622809.png)

Workflow:

Perhaps you can share an example workflow using which the problem can be reproduced rather than just a screenshot?

---

<div class="post-metadata">

**Author:** ![shrey-42](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shrey-42/32/3437_2.png) [@shrey-42](https://community.n8n.io/u/shrey-42)\
**Post date:** [February 20, 2023, 10:00am UTC](https://community.n8n.io/t/bug-in-code-node/23215/4 "2023-02-20T10:00:01Z")

</div>

Hi @MutedJam. Sure, here’s the workflow:

This involves a custom node, Directus ([n8n-nodes-directus - npm](https://www.npmjs.com/package/n8n-nodes-directus)).

Will send you the credentials in a PM.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [February 20, 2023, 10:38am UTC](https://community.n8n.io/t/bug-in-code-node/23215/5 "2023-02-20T10:38:17Z")

</div>

Thank you @shrey-42. Seeing I do not have this node, could you share the JSON output from this node so I can mock the output in the workflow?

---

<div class="post-metadata">

**Author:** ![shrey-42](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shrey-42/32/3437_2.png) [@shrey-42](https://community.n8n.io/u/shrey-42)\
**Post date:** [February 20, 2023, 10:46am UTC](https://community.n8n.io/t/bug-in-code-node/23215/6 "2023-02-20T10:46:33Z")

</div>

The node is also installable as a community node.

But, here’s the node output as printed in the console, by the command `console.log($input.all())`:

```auto
[
    {
        "json": [
            {
                "id": 2,
                "status": "open",
                "user_created": "e3139d0b-9bf4-4003-bf3f-e617bb499966",
                "date_created": "2023-02-19T14:47:49.555Z",
                "user_updated": null,
                "date_updated": null,
                "title": "2",
                "parent": [
                    4,
                    5,
                    6,
                    7
                ]
            }
        ],
        "pairedItem": {
            "item": 0
        }
    }
]

```

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [February 20, 2023, 12:48pm UTC](https://community.n8n.io/t/bug-in-code-node/23215/7 "2023-02-20T12:48:16Z")

</div>

Hi @shrey-42, this looks like your custom node returns an invalid data structure.

This is no longer supported by the Code node and the value of `json` has to be an object rather than an array (see [How n8n structures data | n8n Docs](https://docs.n8n.io/data/data-structure/) for an example). So you’d need to change your node to return a suitable data structure. For example:

```json
[{
    "json": {
        "id": 2,
        "status": "open",
        "user_created": "e3139d0b-9bf4-4003-bf3f-e617bb499966",
        "date_created": "2023-02-19T14:47:49.555Z",
        "user_updated": null,
        "date_updated": null,
        "title": "2",
        "parent": [
            4,
            5,
            6,
            7
        ]
    }
}]

```

This structure would also work in the Code node:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/d/8/d8c0051d074390c0a40df2fa8f362d52da2b0aa5.png)

---

<div class="post-metadata">

**Author:** ![shrey-42](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shrey-42/32/3437_2.png) [@shrey-42](https://community.n8n.io/u/shrey-42)\
**Post date:** [February 21, 2023, 11:48am UTC](https://community.n8n.io/t/bug-in-code-node/23215/8 "2023-02-21T11:48:32Z")

</div>

Hi @MutedJam , thanks for the triage!

Will accommodate for this change.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [May 22, 2023, 11:48am UTC](https://community.n8n.io/t/bug-in-code-node/23215/9 "2023-05-22T11:48:55Z")

</div>

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