Error: The data in "Body Parameters" is no valid JSON. When JSON IS valid

I’m trying to send this JSON via HTTP request:

{
	"row": {
		"id": "610a9a7b9441800004da5988",
		"full_name": "Name",
		"email": "[email protected]",
		"mobile": 000000000,
		"membership_id": "610a9a7b9441800004da5989",
		"membership_status": "active",
		"role_id": "rol-0001",
		"subscription_id": "60e7ab9bdd79d800047d24d0",
		"hubspot_id": "2e6b945d3b212b5ebc249e78b7f73cbe",
		"mixpanel_id": "17b1165e5b720-016cb7b23f6be-2c085940-448e0-17b1165e5c11d",
		"terms_agreement": true,
		"marketing_authorization": false
	},
	"table_name": "users"
}

No matter what I do, I always get the same error. I validated the JSON externally and does not seem to be a problem with that.

I’m using this expression

{
	"row": {
		"id": "{{$node["New member"].json["body"]["id"]}}",
		"full_name": {{JSON.stringify($node["New member"].json["body"]["profile"]["nombre-completo"])}},
		"email": {{JSON.stringify($node["New member"].json["body"]["email"])}},
		"mobile": {{$node["New member"].json["body"]["profile"]["celular"]}},
		"membership_id": "{{$node["New member"].json["body"]["membership"]["id"]}}",
		"membership_status": "{{$node["New member"].json["body"]["membership"]["status"]}}",
		"role_id": {{JSON.stringify($node["New member"].json["body"]["profile"]["rol"])}},
		"subscription_id": "{{$node["New member"].json["body"]["membership"]["subscribed_to"]}}",
		"hubspot_id": "{{$node["New member"].json["body"]["profile"]["huid"]}}",
		"mixpanel_id": {{JSON.stringify($node["New member"].json["body"]["profile"]["mpid"])}},
		"terms_agreement": {{$node["New member"].json["body"]["profile"]["terms"]}},
		"marketing_authorization": {{$node["New member"].json["body"]["profile"]["promo"]}}
	},
	"table_name": "users"
}

And this is the node:

{
  "nodes": [
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "={{$node[\"Set tokens\"].json[\"server\"]}}dtable-server/api/v1/dtables/{{$node[\"Set tokens\"].json[\"id\"]}}/rows/",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={\n\t\"row\": {\n\t\t\"id\": \"{{$node[\"New member\"].json[\"body\"][\"id\"]}}\",\n\t\t\"full_name\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"profile\"][\"nombre-completo\"])}},\n\t\t\"email\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"email\"])}},\n\t\t\"mobile\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"celular\"]}},\n\t\t\"membership_id\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"id\"]}}\",\n\t\t\"membership_status\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"status\"]}}\",\n\t\t\"role_id\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"profile\"][\"rol\"])}},\n\t\t\"subscription_id\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"subscribed_to\"]}}\",\n\t\t\"hubspot_id\": \"{{$node[\"New member\"].json[\"body\"][\"profile\"][\"huid\"]}}\",\n\t\t\"mixpanel_id\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"profile\"][\"mpid\"])}},\n\t\t\"terms_agreement\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"terms\"]}},\n\t\t\"marketing_authorization\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"promo\"]}}\n\t},\n\t\"table_name\": \"users\"\n}"
      },
      "name": "Create new user",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        550,
        330
      ],
      "notesInFlow": true,
      "retryOnFail": true,
      "waitBetweenTries": 300,
      "credentials": {
        "httpHeaderAuth": "Main DB Base Token (R/W)"
      },
      "notes": "Seatable"
    }
  ],
  "connections": {}
}

If it says that it is invalid, I assume it sadly is. Did you check the resolved data and if everything is 100% correct there? I am sadly not able to debug it as all the input data is missing and have so no idea what it will resolve to myself. To be able to debug it, would a mock “New member” node be required with example data. That can be done easiest with a Function-Node.

This is the resolved data, if I copy and paste the resolved data on another workflow, the node passes without errors. But if I use the expression on the original workflow, it gets me an error, let me check if I can mock the data for you to debug.

Here are the nodes with the mock up data:

{
  "nodes": [
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "={{$node[\"Set tokens\"].json[\"server\"]}}dtable-server/api/v1/dtables/{{$node[\"Set tokens\"].json[\"id\"]}}/rows/",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={\n\t\"row\": {\n\t\t\"id\": \"{{$node[\"New member\"].json[\"body\"][\"id\"]}}\",\n\t\t\"full_name\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"profile\"][\"nombre-completo\"])}},\n\t\t\"email\": {{JSON.stringify($node[\"New member\"].json[\"body\"][\"email\"])}},\n\t\t\"mobile\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"celular\"]}},\n\t\t\"membership_id\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"id\"]}}\",\n\t\t\"membership_status\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"status\"]}}\",\n\t\t\"role_id\": \"{{$node[\"New member\"].json[\"body\"][\"profile\"][\"rol\"]}}\",\n\t\t\"subscription_id\": \"{{$node[\"New member\"].json[\"body\"][\"membership\"][\"subscribed_to\"]}}\",\n\t\t\"hubspot_id\": \"{{$node[\"New member\"].json[\"body\"][\"profile\"][\"huid\"]}}\",\n\t\t\"mixpanel_id\": \"{{$node[\"New member\"].json[\"body\"][\"profile\"][\"mpid\"]}}\",\n\t\t\"terms_agreement\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"terms\"]}},\n\t\t\"marketing_authorization\": {{$node[\"New member\"].json[\"body\"][\"profile\"][\"promo\"]}}\n\t},\n\t\"table_name\": \"users\"\n}"
      },
      "name": "Create new user",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        830,
        350
      ],
      "notesInFlow": true,
      "retryOnFail": true,
      "waitBetweenTries": 300,
      "credentials": {
        "httpHeaderAuth": "Main DB Base Token (R/W)"
      },
      "notes": "Seatable"
    },
    {
      "parameters": {
        "filePath": "/root/data/tokens.json"
      },
      "name": "Get tokens",
      "type": "n8n-nodes-base.readBinaryFile",
      "typeVersion": 1,
      "position": [
        480,
        350
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "name": "Set tokens",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        670,
        350
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n { \n json:\n{\n\"headers\": {\n\"x-real-ip\": \"184.72.168.109\",\n\"x-forwarded-for\": \"184.72.168.109\",\n\"host\": \"instantvoices.hooks.n8n.cloud\",\n\"x-forwarded-proto\": \"https\",\n\"x-nginx-proxy\": \"true\",\n\"connection\": \"close\",\n\"content-length\": \"610\",\n\"accept\": \"application/json\",\n\"content-type\": \"application/json\"\n},\n\"params\": {\n},\n\"query\": {\n},\n\"body\": {\n\"id\": \"610c4361e6e830000410a135\",\n\"email\": \"[email protected]\",\n\"profile\": {\n\"nombre-completo\": \"Agustin Albornoz\",\n\"celular\": \"1159244084\",\n\"huid\": \"38476cd9a02f9d7a28471733c024e20b\",\n\"mpid\": \"17b17e6889329a-071ac809f69307-4343363-e1000-17b17e68894803\",\n\"pageuri\": \"www.instantvoices.com/cuenta/registro-locutor\",\n\"pagename\": \"Registro locutor\",\n\"terms\": true,\n\"promo\": false,\n\"rol\": \"rol-0002\",\n\"ip\": \"200.126.195.33\",\n\"id\": \"610c4361e6e830000410a135\"\n},\n\"membership\": {\n\"id\": \"610c4361e6e830000410a136\",\n\"subscribed_to\": \"60e7ab9bdd79d800047d24d0\",\n\"status\": \"active\",\n\"type\": \"free\",\n\"test_mode\": true\n},\n\"created_at\": \"2021-08-05T20:00:33.000Z\"\n}\n}\n}\n]"
      },
      "name": "New member",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        310,
        350
      ]
    }
  ],
  "connections": {
    "Get tokens": {
      "main": [
        [
          {
            "node": "Set tokens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set tokens": {
      "main": [
        [
          {
            "node": "Create new user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New member": {
      "main": [
        [
          {
            "node": "Get tokens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

If I use expression the node gives me the invalid JSON error, if I paste the resolved data, it continues without a problem.

@jan I found the bug, your JSON parser does not recognize a false value if it comes from a node expression, it only recognizes true values. I believe this is a bug on n8n’s side.

Even if I do this workaround, it does not work:
"marketing_authorization": {{($node["New member"].json["body"]["profile"]["promo"]) ? true : false}}

Guess because it is not actually a string and rather a real boolean value. You can make sure that it is a string by adding .toString(). It will then work fine. For example:

{{$node["New member"].json["body"]["profile"]["promo"].toString()}}

Hey @sirland,

Did your issue got resolved? Let us know if you need help :slight_smile:

Yes, thank you @harshil1712 and @jan I had to use a string instead of a boolean value.