Getting actual raw value from json body

Hi, i’m new to n8n, i was testing if i could use n8n to handle some http requests as a man in the middle for credentials validation, i have a webhook wich recieves a json, it work, but when i try to set this value into a new http request node using expression {{$node[“Set”].json[“body”]}} i get a prefix to the raw data and it results into this

[Object: {“id”:“5ef6936c7a3d2cf982409e36”,“data”:[{…

is there a way to get rid of this prefix “[Object: {” using any sort of trick in expression?

thank you, regards.

Hey @aratamagna welcome to the community. Can you share the workflow?

{
  "name": "com-push",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "com/cart",
        "responseMode": "lastNode",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        450,
        350
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "data",
              "value": "={{$node[\"Webhook\"].json[\"body\"][\"data\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        350
      ]
    },
    {
      "parameters": {
        "requestMethod": "PUT",
        "url": "=http://localhost:8080/sessions/{{$node[\"Set\"].json[\"body\"][\"id\"]}}",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{$node[\"Set\"].json[\"body\"]}}"
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        350
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "id": "10"
}

is there a better way tho share a workflow than pasting the raw code btw?

@aratamagna Ok, it has the object prefix cuz it’s an object.

The value of {{$node[“Set”].json[“body”]}} is the object below.

{
   "id": 5ef6936c7a3d2cf982409e36",
   "data": [{  }],
}

I’m guessing you either just want to reference the id of the data and that can be done like this

{{$node[“Set”].json[“body”][“id”]}}

{{$node[“Set”].json[“body”][“data”]}}

About sharing the workflows, yes, this is wat of sharing workflows. For something reason, the workflow you pasted had “ and ” instead of " and ". I had to replace them.

Let me know if that helps.

thanks for the reply, if instead i use {{$node[“Set”].json[“body”][“data”]}} i get the following.

[invalid (Expression is not valid: illegal character)]

after a second attempt i get the following.

[Array: [{“id”:…

is there a way to get that prefix out?

i’ve also tried this expression

{{$node[“Webhook”].json[“body”][“data”].join(’, ')}}

with this result

[object Object], [object Object]

You actually do not have to care about the [Object: ...] it will not be transmitted. It is only a visual indication that shows that it is an actually JavaScript object.
So it will already work as you expect it to work. If you however want to see it (for your visual pleasure) without it you can simply wrap it in JSON.stringify(...).

Here an example with both:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "PUT",
        "url": "=https://enio9cp6joxq.x.pipedream.net",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{$node[\"Function\"].json[\"body\"]}}"
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1000,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.body = {\n  a: 1\n};\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "PUT",
        "url": "=https://enio9cp6joxq.x.pipedream.net",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{JSON.stringify($node[\"Function\"].json[\"body\"])}}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1000,
        350
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          },
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like