Issue with Special Characters in JSON Array when Sending PUT Request

Describe the problem/error/question

I’m currently facing an issue while attempting to send a PUT HTTP request to an API with a JSON body in n8n. The JSON body is expected to include an array of IDs, and each ID should contain in special characters in the form of “”. However, when I preview the JSON expression, the array appears with the special characters, but the actual JSON sent in the request does not include them.

What is the error message (if any)?

No specific error message is received, but the generated JSON in the HTTP request does not match the expected format.

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n Cloud
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

I’m using n8n Cloud, and I’m not aware of other setup configurations

Hey @tungnguyen249,

Have you checked that the data being sent doesn’t include them? It might be worth posting your data to webhook.site to see what arrives as without the " the json array would be invalid so I would be surprised if we were sending it without.

Hi @Jon ,

The input from the previous node is an array of IDs, and I’m attempting to configure the JSON body of the HTTP request.

However, I’m encountering the following error: “ERROR: JSON parameter needs to be a valid JSON.” The expression of the JSON body is configured based on the array of IDs. I’ve attached images to provide a visual representation of my configuration.

I’m looking forward to your expertise!

Hey @tungnguyen249,

Can you share the data so I can give it a test. It could be that you just need to do something like…

{{
  {
    "fields": {
      "Order Lines": $('get_line_data').first().json.ids
    }
  }
}}

Hi @Jon ,

Thank you for your prompt response and suggestion. I’ve made the change as you recommended, updating from $('get_line_data').first().json["ids"] to $('get_line_data').first().json.ids. However, the error “ERROR: JSON parameter needs to be a valid JSON” persists.

Here is a snippet of the data I’m working with:

[
  {
    "total": 231.96,
    "quantity": 4,
    "ids": [
      "recu2i38IKuCZT",
      "recu2i38IKSr5k",
      "recu2i38IKPOEF",
      "recu2i38IKUvCY"
    ]
  }
]

Hey @tungnguyen249,

I have just given it a go using the workflow below and it seems to be ok and has resulted in this: Webhook.site - Test, process and transform emails and HTTP requests

1 Like

Fantastic! The changes in the code worked and everything is functioning as expected. Big thanks for your diligence and effort.

1 Like

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