Json Parse tool can not work to run a expression #6320

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

Originally created by @jiusi9 on GitHub (Oct 24, 2024).

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.10.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I input json data to Json Parse from http request, and want to extract some data, but it always say Unexpected character.

Do not allow to input special strings?
I had test in jsonpath tool online using the following expression.

$..environments[?(@.stage=='staging')]

image

image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @jiusi9 on GitHub (Oct 24, 2024). ### 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.10.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I input json data to **Json Parse** from http request, and want to extract some data, but it always say **Unexpected character**. Do not allow to input special strings? I had test in jsonpath tool online using the following expression. ` $..environments[?(@.stage=='staging')] ` ![image](https://github.com/user-attachments/assets/1dfe4279-07c4-47e1-9be8-69c4b7349abb) ![image](https://github.com/user-attachments/assets/b19ad1b8-009b-4859-b0a2-0b4f1771955d) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:15:12 -05:00
yindo closed this issue 2026-02-21 18:15:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 24, 2024):

The issue you're encountering with the JSON Parse tool in Dify seems to be related to the use of JSONPath expressions. The error message "Unexpected character: ?" suggests that the tool might not be handling the JSONPath syntax as expected.

Dify uses the jsonpath_ng library for handling JSONPath expressions [1]. It's possible that there might be a limitation or a specific syntax requirement in this library that differs from other JSONPath tools you have tested with.

Here are a few things you can try:

  1. Verify Syntax Compatibility: Double-check the syntax of your JSONPath expression to ensure it aligns with the jsonpath_ng library's supported syntax. Some JSONPath implementations have slight variations.

  2. Simplify the Expression: Try simplifying the expression to see if a more basic query works. This can help identify if a specific part of the expression is causing the issue.

  3. Check for Known Issues: Although there are no specific known issues documented for version 0.10.0 regarding JSON parsing, reviewing the library's documentation or any related issues might provide insights.

If these steps don't resolve the issue, consider providing more details or examples to further investigate the problem.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 24, 2024): <!-- Answer --> The issue you're encountering with the JSON Parse tool in Dify seems to be related to the use of JSONPath expressions. The error message "Unexpected character: ?" suggests that the tool might not be handling the JSONPath syntax as expected. Dify uses the `jsonpath_ng` library for handling JSONPath expressions <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/json_process/tools/parse.py)</sup>. It's possible that there might be a limitation or a specific syntax requirement in this library that differs from other JSONPath tools you have tested with. Here are a few things you can try: 1. **Verify Syntax Compatibility**: Double-check the syntax of your JSONPath expression to ensure it aligns with the `jsonpath_ng` library's supported syntax. Some JSONPath implementations have slight variations. 2. **Simplify the Expression**: Try simplifying the expression to see if a more basic query works. This can help identify if a specific part of the expression is causing the issue. 3. **Check for Known Issues**: Although there are no specific known issues documented for version 0.10.0 regarding JSON parsing, reviewing the library's documentation or any related issues might provide insights. If these steps don't resolve the issue, consider providing more details or examples to further investigate the problem. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Oct 24, 2024):

Yes, we have fixed a bunch of errors in v0.10.1

@crazywoola commented on GitHub (Oct 24, 2024): Yes, we have fixed a bunch of errors in v0.10.1
Author
Owner

@jiusi9 commented on GitHub (Oct 25, 2024):

I found root cause.
This tool json_process did not import jsonpath_ng.ext.
/api/core/tools/provider/builtin/json_process/tools/parse.py

This expression $..environments[?(@.stage=='staging')] is a filter extension.

To use the extensions below you must import from jsonpath_ng.ext.

I have done this test. It worked very well.
image

@jiusi9 commented on GitHub (Oct 25, 2024): I found root cause. This tool **json_process** did not import jsonpath_ng.ext. `/api/core/tools/provider/builtin/json_process/tools/parse.py` This expression `$..environments[?(@.stage=='staging')]` is a filter extension. **To use the extensions below you must import from _jsonpath_ng.ext_.** I have done this test. It worked very well. ![image](https://github.com/user-attachments/assets/fe22152c-d09a-4219-83bf-2ad9ea2e5428)
Author
Owner

@jiusi9 commented on GitHub (Oct 25, 2024):

So, Would support this feature and import jsonpath_ng.ext module?

@jiusi9 commented on GitHub (Oct 25, 2024): So, Would support this feature and import jsonpath_ng.ext module?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6320