Help with expressions

Hi,

How do I convert thru expression?
from
[Object: {“filename”:“SDU.DAT”}]
to
{“receipts”: {“filename”: “SDU.DAT”}}

Can you share the expression you are currently using? What you showed us it’s what the expression is resolving to.

{{$node[“Function”].json[“receipts”]}}

You can do: {{ { “receipts”: $node[“Function”].json[“receipts”] } }}

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://webhook.site/0054b04d-2ae2-4461-805d-4d2800b6f51e",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{ { \"receipts\": $node[\"Function\"].json[\"receipts\"] } }}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        740,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      receipts: {\n        name: 'aaaa`'\n      }\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hi Ricardo,

Even with this solution I am getting the following result to be passed to the next node.

[Object: {“receipts”:{“name”:“aaaa`”}}]

What I need is without Object i.e. {“receipts”:{“name”:“aaaa`”}}

Do not worry about that. It’s just the expression editor telling you that is resolving to an object. But that it’s not being passed.

Problem is I am calling flask API with result of expression, its not able to recognize JSON input, It is working if I manually remove and send static input. Anyway we can send plain text without [Object in there?

Are you using the HTTP node? if so can you show me how you are using it?

BodyContentType as JSON, JSON/Raw is checked, POST call, sending expression result as Body parameter

In the example that I sent you above, I did exactly that. Just run it and go here to see the request.

Added the workflow again below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://webhook.site/0054b04d-2ae2-4461-805d-4d2800b6f51e",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{ { \"receipts\": $node[\"Function\"].json[\"receipts\"] } }}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      receipts: {\n        name: 'aaaa`'\n      }\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        520,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thank you so much Ricardo, appreciate your patience. Its working now. I had to change program slightly, now it works with the way you sent.

Glad that it worked. Have fun.