# JSON error using code node after subworkflow execution

**URL:** <https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386>\
**Category:** Questions\
**Tags:** bug:confirmed\
**Created:** [August 19, 2026, 11:59am UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386 "2026-08-19T11:59:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgggr](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jgggr/32/37500_2.png) [@jgggr](https://community.n8n.io/u/jgggr)\
**Post date:** [August 19, 2026, 11:59am UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/1 "2026-08-19T11:59:43Z")

</div>

## Describe the problem/error/question

After running a subworkflow I receive a json object. If i try to make a simple edit using node code, i get an error for the JSON output: Invalid output format [item 0] An output item contains the reserved key json. To get around this, please wrap each item in an object, under a key called json.  
The only solution i found was to delete the metadata key from the item.  
I believe this is not expected behaviour.

`for (const item of $input.all()) {`  
`delete item.metadata;`  
`}`  
`return $input.all();`

## Please share your workflow

## Share the output returned by the last node

Invalid output format [item 0]  
An output item contains the reserved key json. To get around this, please wrap each item in an object, under a key called json.

## Information on your n8n setup

- **n8n version: 2.19.2**
- **Database (default: SQLite): postgres**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main): ?**
- **Running n8n via (Docker, npm, n8n cloud, desktop app): docker**
- **Operating system: ubuntu**

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/196425_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [August 19, 2026, 12:00pm UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/2 "2026-08-19T12:00:08Z")

</div>

Hey @jgggr, while you wait for a response, here are some things that might help:

> **Suggested resources**
>
> _Automatically matched to your question._
> 
> **Docs:**
> 
> - [Using the Code node](https://docs.n8n.io/build/code-in-n8n/using-the-code-node)
> - [n8n@1.22.4](https://docs.n8n.io/changelog/release-notes-1.x#n8n1224)
> - [n8n@2.22.1](https://docs.n8n.io/changelog/release-notes-2.x#n8n2221)
> 
> **Forum:**
> 
> - [A ‘json’ property isn’t an object](https://community.n8n.io/t/285894)
> - [Binary File Data Not Accessible When Passed via Execute Sub-Workflow Node](https://community.n8n.io/t/142192)
> - [The ‘JSON Output’ in item 0 contains invalid JSON in the Edit Fields Node](https://community.n8n.io/t/128422)

@David_Streuli, @Matze202 - you’ve helped with similar issues before, can you take a look?

_Automatically suggested by n8n’s community bot. It’s a pilot - [please share feedback here](https://community.n8n.io/t/pilot-forum-helper-bot/304669)._

---

<div class="post-metadata">

**Author:** ![Anshul\_Namdev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/anshul_namdev/32/178229_2.png) [@Anshul\_Namdev](https://community.n8n.io/u/Anshul_Namdev)\
**Post date:** [August 19, 2026, 12:04pm UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/3 "2026-08-19T12:04:15Z")

</div>

Hi @jgggr  
The Execute Sub-workflow node adds a top-level `metadata` key to every item it returns, which is what the “View sub-execution” link uses, and the Code node only allows `json`, `binary`, `pairedItem` and `error` as top-level keys on an output item, so `return $input.all()` gets rejected. Build the output items instead of returning the input ones:

```auto
return $input.all().map((item, i) => {
  const json = { ...item.json };
  if (json.agent_name === "example") json.agent_name = "other example";
  return { json, pairedItem: i };
});

```

`pairedItem` keeps item linking working for the nodes after it.

> **[Understand n8n's data structure | Build | n8n Docs](https://docs.n8n.io/build/work-with-data/understand-n8ns-data-structure)**

This was reported upstream and closed as stale, so building the items is the way around it for now:

> <https://github.com/n8n-io/n8n/issues/13087>
>
> \### Bug Description
> 
> Code node does not allow the return of Subworkflow items be…cause they have \`metadata\` key
> 
> Solution would be to add \`metadata\` to \`REQUIRED\_N8N\_ITEM\_KEYS\` in nodes/Code/Sandbox.ts
> 
> \### To Reproduce
> 
> Run a subworkflow, then return subworkflow.all() in Code node
> 
> \### Expected behavior
> 
> Code node allows items to have \`metadata\` key.
> 
> \### Operating System
> 
> Ubuntu
> 
> \### n8n Version
> 
> 1.76.3
> 
> \### Node.js Version
> 
> 20.18.2
> 
> \### Database
> 
> SQLite (default)
> 
> \### Execution mode
> 
> main (default)

---

<div class="post-metadata">

**Author:** ![n8n](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/n8n/32/196425_2.png) [@n8n](https://community.n8n.io/u/n8n)\
**Post date:** [August 19, 2026, 12:30pm UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/5 "2026-08-19T12:30:21Z")

</div>

Thanks for letting us know about this, We have created `NODE-5788` as the internal dev ticket to look into it.

---

<div class="post-metadata">

**Author:** ![jgggr](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jgggr/32/37500_2.png) [@jgggr](https://community.n8n.io/u/jgggr)\
**Post date:** [August 23, 2026, 2:13pm UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/6 "2026-08-23T14:13:28Z")

</div>

Thank you for your reply.

The solution workaround you describe I believe is the same thing as i’ve suggested (to delete the metadata key) right?

The GitHub issue you mentioned is spot on the problem I’ve described.

---

<div class="post-metadata">

**Author:** ![Anshul\_Namdev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/anshul_namdev/32/178229_2.png) [@Anshul\_Namdev](https://community.n8n.io/u/Anshul_Namdev)\
**Post date:** [August 23, 2026, 2:32pm UTC](https://community.n8n.io/t/json-error-using-code-node-after-subworkflow-execution/308386/7 "2026-08-23T14:32:27Z")

</div>

Same idea, and for the items that actually get cleaned the outcome is identical. The version in the workflow JSON you pasted isn’t equivalent though: `delete item.metadata` sits inside the `case "example":` branch, so only items whose `agent_name` matches get cleaned and every other item still carries `metadata` and trips the same error. Building the output item covers all of them without a branch, and it keeps working if the node ever returns another top-level key alongside `metadata`.
