# How to get JSON from last node?

**URL:** <https://community.n8n.io/t/how-to-get-json-from-last-node/62>\
**Category:** Questions\
**Created:** [September 26, 2019, 11:24am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62 "2019-09-26T11:24:28Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 26, 2019, 11:24am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/1 "2019-09-26T11:24:28Z")

</div>

I make a http request to get a json object. I now like to make another http request to send this object to another endpoint. But I’m not able to get the same data structure into my HTTP request:

 ![json](https://europe1.discourse-cdn.com/n8n/original/1X/0274e76dcfef8f5f893a29b474db201396e3b3e5.png)

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 26, 2019, 11:44am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/2 "2019-09-26T11:44:17Z")

</div>

Hi!

It should actually work exactly like that. A good page to test that is this one:  
[https://httpbin.org/anything](https://httpbin.org/anything)  
That one sends as a response the same data you did send to it. I just tested it (to be sure I am telling you the truth) and it worked fine.

The `[Object:...]` in the result is not exactly the data which does get send there. It will not send `[Object:...]` it is just a way to visually show people that it sets an actual JavaScript-Object and not some kind of string, number, boolean. If you want it to display only the data and not the `[Object:...]` you can simply add a `JSON.stringify`. Then it will be converted to a string and will be displayed as such.

Sorry is apparently not obvious. Have to add proper documentation about that or find a better way to display it to make it clearer.

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 26, 2019, 11:45am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/3 "2019-09-26T11:45:56Z")

</div>

Ah, got you. Thanks, I will test it right away 🙂

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 27, 2019, 8:20am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/4 "2019-09-27T08:20:02Z")

</div>

I used [https://webhook.site](https://webhook.site) to get the response. But it is not working, this is my response: “[object Object]”

This is the expression I created:

```
{
  "properties":{},
  "routing_key":"create",
  "payload":"{{$node["HTTP Request"].data}}",
  "payload_encoding":"string"
}

```

and the output is:

```
{
  "properties": {},
  "routing_key": "create",
  "payload": "[object Object]",
  "payload_encoding": "string"
}
```

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 27, 2019, 9:57am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/5 "2019-09-27T09:57:19Z")

</div>

Got it:

```
{
  "properties":{},
  "routing_key":"create",
  "payload":"{{JSON.stringify($node["HTTP Requestt"].data ).replace(/"/g, "\\\"")}}",
  "payload_encoding":"string"
}
```

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 27, 2019, 10:21am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/6 "2019-09-27T10:21:45Z")

</div>

That does not seem like the correct answer for me.

This one works totally fine like written above without any stringify or replace:

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 27, 2019, 10:40am UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/7 "2019-09-27T10:40:54Z")

</div>

Btw. to send the data you want to send above you would simply do this:

```auto
{ 
  "properties": {}, 
  "routing_key": "create", 
  "payload": {{JSON.stringify($node["HTTP Requestt"].data)}}, 
  "payload_encoding": "string"
}

```

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 27, 2019, 2:15pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/8 "2019-09-27T14:15:06Z")

</div>

I tested this, it only works for me with the replacement.

```
{{JSON.stringify($node["REQUEST"].data ).replace(/"/g, "\\\"")}}
{\"id\":\"5d8....1989\",\"date\":\"2019-09-27T14:11:32.8998044+00:00\",\"Number\":\"900..

{{JSON.stringify($node["REQUEST"].data )}}
{"id":"5d8......1989","date":"2019-09-27T14:11:32.8998044+00:00","Number":"900..
```

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 27, 2019, 3:01pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/9 "2019-09-27T15:01:16Z")

</div>

Sorry still does not make any sense to me.

Did you really test what I did post above in n8n? Exactly like I did add it? So copied the JSON in n8n so that it creates the nodes and connections and then press “Execute”. Because then it has to work!

Maybe all you did is to remove the replace but still left the quotes around it?

Here again an example with the full data you apparently want to send:

If you do what you described above, you will get this data displayed on webhook.site:  
 ![Screenshot%20from%202019-09-27%2016-44-24](https://europe1.discourse-cdn.com/n8n/original/1X/61c65b3c9ab1e5eef326a7e313977b6309e7e751.png)

But then the payload has to get JSON.stringified.

What you normally want is this:  
 ![Screenshot%20from%202019-09-27%2016-44-38](https://europe1.discourse-cdn.com/n8n/original/1X/02fcf63a02bc13503cb90afd5db7113a597fdf7c.png)

Sure it is possible that some endpoint in the Internet expects the data as a string which it has to be JSON.stringified but that is probably not what the most people would want when they see this question. So fear that the answer you did set as solution would cause problems for people that try it as it will not result in “full” JSON. It would be JSON with a string inside which can be parsed to JSON.

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 27, 2019, 4:09pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/10 "2019-09-27T16:09:16Z")

</div>

I see your solution is working (with your JSON) but with mine I get validation errors:

```
Error: Parse error on line 4:
...ate",	"payload":"{"id":"5d8e31ea6bd1135
----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'

```

This is why I escape mine - my endpoint seams to have no problems with the escaped JSON. As a side note, my JSON is also valid if I not need to put it in this structure.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 27, 2019, 4:11pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/11 "2019-09-27T16:11:42Z")

</div>

Yes that error makes sense if you still have the quotes around the expression. So you just have to change:

```auto
"payload": "{{JSON.stringify($node["HTTP Requestt"].data)}}",

```

to

```auto
"payload": {{JSON.stringify($node["HTTP Requestt"].data)}},

```

---

<div class="post-metadata">

**Author:** ![jwillmer](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jwillmer/32/46_2.png) [@jwillmer](https://community.n8n.io/u/jwillmer)\
**Post date:** [September 27, 2019, 4:12pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/12 "2019-09-27T16:12:43Z")

</div>

Now I got you 💥

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [September 27, 2019, 4:13pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/13 "2019-09-27T16:13:24Z")

</div>

Great, now the worls makes sense for me again 😉

---

<div class="post-metadata">

**Author:** ![jtemporal](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jtemporal/32/61_2.png) [@jtemporal](https://community.n8n.io/u/jtemporal)\
**Post date:** [October 8, 2019, 5:35pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/14 "2019-10-08T17:35:49Z")

</div>

```auto
"payload": "{{JSON.stringify($node['HTTP Requestt'].data)}}",

```

would work as well, right?

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [October 8, 2019, 9:22pm UTC](https://community.n8n.io/t/how-to-get-json-from-last-node/62/15 "2019-10-08T21:22:57Z")

</div>

No that would cause the same problems. As the result would be something like this:

```auto
{
  "payload" : "{ "the data": "asdf" }"
}

```

So you have again quotes in quoted text.
