Nested json read as [object Object]

Describe the problem/error/question

I build a workflow which execute an http api call and return as a response an array of objects, than i want to send this array of objects to a discord message but the message is published with [object Object].
This is the mark down i created

## Alert Details
- **Campaign items**: {{$json}} 
- **Time of Occurrence**: {{ new Date() }}

this is the json response i am get

[
  {
    "items": [
      {
       ...data
      },
      {
      ...data
      }
    ],
    "count": 2,
    "skipped": "0"
  }
]

What do i miss?

Share the output returned by the last node


[
{
"success": 
true
}
]

Information on your n8n setup

  • **n8n version:1.25.0
  • **Database (default: SQLite):postgres
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
  • Operating system:

Can you please share the workflow as that will help see the issue better. This could be a number of things so it would help to see the implementation. Please also share the JSON as the embedded workflows remove your pinned data for security

To help troubleshoot you can wrap what you’re currently returning with {{ JSON.stringify( $json.key ) }}

Unfortunately i can not share it since we run on a hosted instance and it contain some sensitive data. there is a way to copy the nodes without the data?

not sure if the image is helping

I will at lest need to see the discord node and a sample of the JSON. You can copy the json and censor all sensitive info. You can copy and paste just one node

this is the edit expression window on the discord node


and another image of the all node

replace the expressions with this and let me know how it works

{{ $json.items.join(', ') }} This makes the list a string and separates each item with a comma and space

{{ $now.toFormat('t D') }} $now gets current time in a DateTime obj. .toFormat('t D') turns it to this format “9:14 AM 3/7/2024”. You can format the date however you want, ref the luxon docs for their syntax.

Thank you for your help, looks like it is the same issue. see the image, maybe it is realted to how discord reading it?
image

Join won’t work with complex objects :slight_smile:
use the {{ JSON.stringify($json.items) }}

1 Like

It’s because you have arrays or objects in that array which i didn’t notice. When you try to add something like an array [ "thing 1", "thing 2" ] or an object { "thing 1":"this", "thing 2":"that"} it will return something like [object object].

Can you share a sample of what is in the items of the list? You can remove sensitive information first.

Like @barn4k said you’ll need to use the {{ JSON.stringify($json.items) }} as a catch-all to convert any object to a string, but it won’t be particularly pretty usually.

If you send the JSON and an example of what you want it to look like in the message we can help you with a method that gets you there. (provided the objects in the list are consistant)

1 Like

Sure
this is an example

[
  {
    "items": [
      {
        "id": "10212940",
        "action_id": "9e3debaef041959138a86de6f9c59aeb7bcc68c95086d85faa02896a891efa5f",
        "tenant_id": "gsoofcqv7fl8nrxbz9ba5",
        "application_id": "z3pnuj05yb2vyosolctx5",
        "client_id": "zsKFyTytYtZL3R8hcvQQ7",
        "user_id": "test2024-03-0315:47:51.413706uid",
        "correlation_id": null,
        "device_id": "test2024-03-0315:47:51.413706",
        "device_fingerprint": "6075bdb106584993a054a31f853e79715f22135e09e0a5fd8442981de2a32927",
        "risk_score": "96.8",
        "timestamp": "1709480876876",
        "action_type": "authenticated",
        "ip": "24.32.31.38",
        "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/104.0.5112.48 Safari/537.36",
        "ip_country": "US",
        "ip_company_name": "Optimum",
        "ip_asn_name": "Optimum",
        "recommendation": "DENY",
        "rules": [],
        "features_agg_data": {
         ...
        }
      },
      {
        "id": "10212939",
        "action_id": "9a8bfcfaddbf1aca1d20161f33dcd064c6e1128f78a499116484ad531c1eee59",
        "tenant_id": "gsoofcqv7fl8nrxbz9ba5",
        "application_id": "z3pnuj05yb2vyosolctx5",
        "client_id": "zsKFyTytYtZL3R8hcvQQ7",
        "user_id": "test2024-03-0315:47:57.063477uid",
        "correlation_id": null,
        "device_id": "test2024-03-0315:47:57.063477",
        "device_fingerprint": "6075bdb106584993a054a31f853e79715f22135e09e0a5fd8442981de2a32927",
        "risk_score": "96.3",
        "timestamp": "1709480882347",
        "action_type": "authenticated",
        "ip": "24.32.31.38",
        "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/104.0.5112.48 Safari/537.36",
        "ip_country": "US",
        "ip_company_name": "Optimum",
        "ip_asn_name": "Optimum",
        "recommendation": "DENY",
        "rules": [
         ...strings
        ],
        "features_agg_data": {
         ....
        }
      }
    ],
    "count": 2,
    "skipped": "0"
  }
]

First you’ll want to split out the items array then you can just access any info you want with dot notation.

After the split out node, you can just use {{ $json.id }} or {{ $json.action_id }} to get any info you want

2 Likes

There is no way to use the json with out the split node? what if i want to pass the all json body as it to other node? it will work?

Do you want ALL of the information in one message? Like every piece of data in there?

Do you want both pieces of data in the same message or do you want one message for each item in the list?

all object in one message

As mentioned before use {{ JSON.stringify($json.items) }} for that

but when i use it like your suggestion i am get the following error, see image attached

NodeOperationError: 
    at Object.parseDiscordError (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/helpers/utils.js:66:12)
    at Object.execute (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/actions/webhook/sendLegacy.operation.js:125:51)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Object.router (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/actions/router.js:69:26)
    at Object.execute (/usr/local/lib/node_modules/n8n/packages/nodes-base/dist/nodes/Discord/v2/DiscordV2.node.js:19:16)
    at Workflow.runNode (/usr/local/lib/node_modules/n8n/packages/workflow/dist/Workflow.js:700:19)
    at /usr/local/lib/node_modules/n8n/packages/core/dist/WorkflowExecute.js:656:53
    at /usr/local/lib/node_modules/n8n/packages/core/dist/WorkflowExecute.js:1058:20

Please let me know if you want every piece of data from this or just one a few, for example just the ID field.

I want to ask first because that would make this much simpler.

If not i’ll make a code node that processes it for you

i want each item and all fields. i do not want to exclude any information.