# Invalid JSON in HTTP Request node

**URL:** <https://community.n8n.io/t/invalid-json-in-http-request-node/27245>\
**Category:** Questions\
**Tags:** http-request\
**Created:** [June 17, 2023, 11:28pm UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245 "2023-06-17T23:28:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodmontgt](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/rodmontgt/32/12519_2.png) [@rodmontgt](https://community.n8n.io/u/rodmontgt)\
**Post date:** [June 17, 2023, 11:28pm UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/1 "2023-06-17T23:28:31Z")

</div>

## Describe the problem/error/question

Hey n8n team, thanks in advance for your help,  
I’m passing the data generated from Set Node to HTTP Request Node, but I got that error in the image below, I already tried set in the HTTP node in RAW mode with application/json as well as JSON mode with no luck

## What is the error message (if any)?

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/5/d/5d78f0653d22d5eed9882e421c6fdb88cd36115a.png)

## Please share your workflow

```auto
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

```

## Share the output returned by the last node

```auto
[
  {
    "Dte": {
      "datosGenerales": {
        "tipo": "\"FACT\"",
        "fechaHoraEmision": "\"2023-06-16T18:28:11\"",
        "codigoMoneda": "\"GTQ\""
      },
      "emisor": {
        "direccion": {
          "direccion": "\"Ciudad\"",
          "codigoPostal": "\"01001\"",
          "municipio": "\"\"",
          "departamento": "\"\"",
          "pais": "\"GT\""
        },
        "nitEmisor": "\"107902281\"",
        "nombreEmisor": "\"DUMMY\"",
        "codigoEstablecimiento": "\"0\"",
        "nombreComercial": "\"DUMMY\"",
        "correoEmisor": "\"dummy@DUMMY.com\"",
        "afiliacionIVA": "\"GEN\""
      },
      "receptor": {
        "direccion": {
          "direccion": "\"Ciudad \"",
          "codigoPostal": "01001"
        }
      }
    }
  }
]

```

## Information on your n8n setup

- **n8n version:** 0.231.2
- **Database (default: SQLite):** PostgreSQL
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):** own
- **Running n8n via (Docker, npm, n8n cloud, desktop app):** Docker
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 20, 2023, 9:03am UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/3 "2023-06-20T09:03:54Z")

</div>

Hi @rodmontgt, I am sorry to hear you’re having trouble. This error suggest that n8n can’t process the response data it receives from your API.

In a first step, you could try setting the response format (under _Options → Add Option → Response_) to `Text` like so:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/6/5/656c7c376e6f37881d076146bfe87cd24fc766ee.png)

This should prevent n8n from trying to parse the response as JSON data.

---

<div class="post-metadata">

**Author:** ![rodmontgt](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/rodmontgt/32/12519_2.png) [@rodmontgt](https://community.n8n.io/u/rodmontgt)\
**Post date:** [June 21, 2023, 1:06am UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/4 "2023-06-21T01:06:51Z")

</div>

Sadly I got this error:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/b/3/b3b6f18679686b8dc89fe0a7c061d956be530cfe.png)

It works with the same payload but on Postman, it returns a XML payload if everything is OK

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/4/c/4c1ddc0c860e200bffef7172acd32df96589a1d5.png)

Any ideas?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 21, 2023, 7:53am UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/5 "2023-06-21T07:53:19Z")

</div>

Hi @rodmontgt, I am afraid I can’t reproduce this. Fetching XML data should work fine in general, I tested this using the below workflow:

This is my result:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/7/6/769bfc83f2a2264586407c8f3d2b55344335b7fc.png)

Is there any chance you can share an example using which your problem can be reproduced? You can for example use a service such as [webhook.site](https://webhook.site) to create a dummy API endpoint returning XML data with anything confidential redacted (click the _Edit_ button to mock a response).

---

<div class="post-metadata">

**Author:** ![rodmontgt](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/rodmontgt/32/12519_2.png) [@rodmontgt](https://community.n8n.io/u/rodmontgt)\
**Post date:** [June 23, 2023, 4:49pm UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/6 "2023-06-23T16:49:35Z")

</div>

Hi again, thanks for your help,  
I already tried putting the raw data in the JSON body of the HTTP request node, and it works like a charm, so the problem is with the data that I’m sending dynamically taken from the previous node.

I realized I’m sending data inside brackets, like an array, but I need to send the data without those objects.

I tried removing the brackets with the following ways but with no luck:

I tried this code outside n8n and is working but inside n8n it gives me an error:

```auto
var json = $input.all();
var parsedJson = JSON.parse(json);
var jsonString = JSON.stringify(parsedJson[0]);

return jsonString;

```

or with this:

```auto
// Remove outer brackets
const jsonString = JSON.stringify(jsonData[0]);

// Output data
return jsonString;

```

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/7/f/7f3c8f497756b068299735f7dccf4c005d26eabd.png)

This is the input data

```auto
[
  {
    "Dte": {
      "datosGenerales": {
        "tipo": "\"FACT\"",
        "fechaHoraEmision": "\"2023-06-16T18:28:11\"",
        "codigoMoneda": "\"GTQ\""
      },
      "emisor": {
        "direccion": {
          "direccion": "\"Ciudad\"",
          "codigoPostal": "\"01001\"",
          "municipio": "\"\"",
          "departamento": "\"\"",
          "pais": "\"GT\""
        },
        "nitEmisor": "\"107902281\"",
        "nombreEmisor": "\"SOCIEDAD ANONIMA\"",
        "codigoEstablecimiento": "\"0\"",
        "nombreComercial": "\"SOCIEDAD ANONIMA\"",
        "correoEmisor": "\"dummy@dummy.com\"",
        "afiliacionIVA": "\"GEN\""
      },
      "receptor": {
        "direccion": {
          "direccion": "\"Ciudad \"",
          "codigoPostal": "1",
          "municipio": "\"\"",
          "departamento": "\"\"",
          "pais": "\"GT\""
        },
        "idReceptor": "\"CF\"",
        "nombreReceptor": "\"Consumidor Final\"",
        "correoReceptor": "\"cf@dummy.com\""
      },
      "items": []
    }
  },
  {
    "items": {
      "bienOServicio": "\"B\"",
      "cantidad": 1,
      "unidadMedida": "\"UN\"",
      "descripcion": "T-Shirt Three",
      "precioUnitario": "15.00",
      "precio": "15.00",
      "descuento": "0.00",
      "total": "15.00",
      "impuestos": {
        "nombreCorto": "\"IVA\"",
        "codigoUnidadGravable": "1",
        "montoGravable": 13.392857142857142,
        "montoImpuesto": 1.607142857142857
      }
    }
  },
  {
    "items": {
      "bienOServicio": "\"B\"",
      "cantidad": 1,
      "unidadMedida": "\"UN\"",
      "descripcion": "Mug BHeart",
      "precioUnitario": "5.00",
      "precio": "5.00",
      "descuento": "0.00",
      "total": "5.00",
      "impuestos": {
        "nombreCorto": "\"IVA\"",
        "codigoUnidadGravable": "1",
        "montoGravable": 4.4642857142857135,
        "montoImpuesto": 0.5357142857142856
      }
    }
  }
]

```

and this is the expected output data:

```auto
  {
    "Dte": {
      "datosGenerales": {
        "tipo": "\"FACT\"",
        "fechaHoraEmision": "\"2023-06-16T18:28:11\"",
        "codigoMoneda": "\"GTQ\""
      },
      "emisor": {
        "direccion": {
          "direccion": "\"Ciudad\"",
          "codigoPostal": "\"01001\"",
          "municipio": "\"\"",
          "departamento": "\"\"",
          "pais": "\"GT\""
        },
        "nitEmisor": "\"107902281\"",
        "nombreEmisor": "\"SOCIEDAD ANONIMA\"",
        "codigoEstablecimiento": "\"0\"",
        "nombreComercial": "\"SOCIEDAD ANONIMA\"",
        "correoEmisor": "\"dummy@dummy.com\"",
        "afiliacionIVA": "\"GEN\""
      },
      "receptor": {
        "direccion": {
          "direccion": "\"Ciudad \"",
          "codigoPostal": "1",
          "municipio": "\"\"",
          "departamento": "\"\"",
          "pais": "\"GT\""
        },
        "idReceptor": "\"CF\"",
        "nombreReceptor": "\"Consumidor Final\"",
        "correoReceptor": "\"cf@dummy.com\""
      },
      "items": []
    }
  },
  {
    "items": {
      "bienOServicio": "\"B\"",
      "cantidad": 1,
      "unidadMedida": "\"UN\"",
      "descripcion": "T-Shirt Three",
      "precioUnitario": "15.00",
      "precio": "15.00",
      "descuento": "0.00",
      "total": "15.00",
      "impuestos": {
        "nombreCorto": "\"IVA\"",
        "codigoUnidadGravable": "1",
        "montoGravable": 13.392857142857142,
        "montoImpuesto": 1.607142857142857
      }
    }
  },
  {
    "items": {
      "bienOServicio": "\"B\"",
      "cantidad": 1,
      "unidadMedida": "\"UN\"",
      "descripcion": "Mug BHeart",
      "precioUnitario": "5.00",
      "precio": "5.00",
      "descuento": "0.00",
      "total": "5.00",
      "impuestos": {
        "nombreCorto": "\"IVA\"",
        "codigoUnidadGravable": "1",
        "montoGravable": 4.4642857142857135,
        "montoImpuesto": 0.5357142857142856
      }
    }
  }

```

---

<div class="post-metadata">

**Author:** ![rodmontgt](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/rodmontgt/32/12519_2.png) [@rodmontgt](https://community.n8n.io/u/rodmontgt)\
**Post date:** [June 28, 2023, 1:22am UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/7 "2023-06-28T01:22:09Z")

</div>

I’m afraid I was sending an incorrect formatted JSON, after fixing the JSON I was able to send it without stringify or parse functions.

In the body field just typed:

```auto
{{ $input.first().json }}

```

and got the XML data as expected

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/f/7/f7a1a47221f72e4dda5158e7a6bd2cfbe64c3c13.png)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 5, 2023, 1:22am UTC](https://community.n8n.io/t/invalid-json-in-http-request-node/27245/8 "2023-07-05T01:22:53Z")

</div>

Closed on July 5, 2023, 1:22am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
