Invalid JSON string when using Array[String] in HTTP request node #7735

Closed
opened 2026-02-21 18:22:06 -05:00 by yindo · 4 comments
Owner

Originally created by @bowenliang123 on GitHub (Jan 15, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.1

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

  1. Generate an string array from Python Executor
def main() -> dict:
    return {
        "result": ["a","b"],
    }
  1. Use the string array variable in HTTP Request node
image image

✔️ Expected Behavior

No response

Actual Behavior

image

No response

Originally created by @bowenliang123 on GitHub (Jan 15, 2025). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.15.1 ### Cloud or Self Hosted Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce 1. Generate an string array from Python Executor ``` def main() -> dict: return { "result": ["a","b"], } ``` 2. Use the string array variable in HTTP Request node <img width="890" alt="image" src="https://github.com/user-attachments/assets/11e05244-9bf6-4e19-8581-7af2732c99ba" /> <img width="894" alt="image" src="https://github.com/user-attachments/assets/645947e1-6457-464c-aa57-97b16fdd92a3" /> ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior <img width="1296" alt="image" src="https://github.com/user-attachments/assets/ff567883-208c-4bfc-abe1-caf52c3de229" /> _No response_
yindo added the 🐞 bug label 2026-02-21 18:22:06 -05:00
yindo closed this issue 2026-02-21 18:22:06 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 15, 2025):

I found a similar unsolved discussion titled JSON not recognizing a string item from an iteration, which might be related to the issue you're experiencing [1].

To address the JSON parsing error when using a string array in the HTTP Request node in Dify version 0.15.1, ensure that the JSON string is correctly formatted before it is parsed. The _init_body method in the Executor class attempts to parse the JSON string using json.loads(json_string, strict=False). If the JSON string is not correctly formatted, a json.JSONDecodeError will be raised.

Here's a snippet of the relevant code:

case "json":
    if len(data) != 1:
        raise RequestBodyError("json body type should have exactly one item")
    json_string = self.variable_pool.convert_template(data[0].value).text
    try:
        json_object = json.loads(json_string, strict=False)
    except json.JSONDecodeError as e:
        raise RequestBodyError(f"Failed to parse JSON: {json_string}") from e
    self.json = json_object

Ensure that the JSON string is valid and properly formatted before it is passed to the HTTP Request node. If the JSON string is generated dynamically, verify that all necessary escaping and formatting are correctly applied. If the error persists, inspect the JSON string being passed to identify any syntax issues [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot[bot] commented on GitHub (Jan 15, 2025): <!-- Answer --> I found a similar unsolved discussion titled [JSON not recognizing a string item from an iteration](https://github.com/langgenius/dify/discussions/9836), which might be related to the issue you're experiencing <sup>[[1]](https://github.com/langgenius/dify/discussions/9836)</sup>. To address the JSON parsing error when using a string array in the HTTP Request node in Dify version 0.15.1, ensure that the JSON string is correctly formatted before it is parsed. The `_init_body` method in the `Executor` class attempts to parse the JSON string using `json.loads(json_string, strict=False)`. If the JSON string is not correctly formatted, a `json.JSONDecodeError` will be raised. Here's a snippet of the relevant code: ```python case "json": if len(data) != 1: raise RequestBodyError("json body type should have exactly one item") json_string = self.variable_pool.convert_template(data[0].value).text try: json_object = json.loads(json_string, strict=False) except json.JSONDecodeError as e: raise RequestBodyError(f"Failed to parse JSON: {json_string}") from e self.json = json_object ``` Ensure that the JSON string is valid and properly formatted before it is passed to the HTTP Request node. If the JSON string is generated dynamically, verify that all necessary escaping and formatting are correctly applied. If the error persists, inspect the JSON string being passed to identify any syntax issues <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/http_request/executor.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/4083ac6f-7611-4b95-938c-cd3efc860084?feedback_type=other)</sup>
Author
Owner

@bowenliang123 commented on GitHub (Jan 15, 2025):

Your suggested case is not using any of string array instance.
Furthermore, we should never pervent segement usage of virables in HTTP node's JSON body, by forcing it pre-generated.

@bowenliang123 commented on GitHub (Jan 15, 2025): Your suggested case is not using any of string array instance. Furthermore, we should never pervent segement usage of virables in HTTP node's JSON body, by forcing it pre-generated.
Author
Owner

@mrkenknight commented on GitHub (Jan 15, 2025):

/api/core/workflow/nodes/http_request/executor.py
Change line:
json_object = json.loads(json_string, strict=False)

To:
json_object = json.loads(json_string.replace("'", '"'), strict=False)

This work for me

@mrkenknight commented on GitHub (Jan 15, 2025): /api/core/workflow/nodes/http_request/executor.py Change line: json_object = json.loads(json_string, strict=False) To: json_object = json.loads(json_string.replace("'", '"'), strict=False) This work for me
Author
Owner

@crazywoola commented on GitHub (Jan 20, 2025):

Image

This should do the trick as well.

@crazywoola commented on GitHub (Jan 20, 2025): <img width="590" alt="Image" src="https://github.com/user-attachments/assets/ebec1543-f906-45d8-97a9-4f612f1d18bd" /> This should do the trick as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7735