Skip to content

fix(json_process): delete array elements by matched indices - #4150

Open
Yzzz88 wants to merge 1 commit into
langgenius:mainfrom
Yzzz88:fix/json-delete-array-indices
Open

Yzzz88 wants to merge 1 commit into
langgenius:mainfrom
Yzzz88:fix/json-delete-array-indices

Conversation

@Yzzz88

@Yzzz88 Yzzz88 commented Oct 30, 2026

Copy link
Copy Markdown

Summary

Fixes #4149

JSON Delete currently removes array elements by value equality. Deleting $.items[2] from {"items": [1, 2, 1]} therefore returns {"items": [2, 1]} instead of {"items": [1, 2]}.

Collect the original matching positions per array, normalize negative indices, deduplicate and delete in descending order. This keeps unselected items and handles unordered indices and slices without index shifts. Add real-SDK offline regression tests and a README example.

Release Notes

Fix JSON Delete removing the wrong array element when equal values occur. Array deletions now respect the positions selected by JSONPath, including negative indices, repeated selections, slices and nested arrays.

Change Type

  • Documentation / non-plugin change
  • Non-LLM plugin (tools, extensions, datasource, etc.)
  • LLM plugin

Screenshots / Videos

Not applicable: deterministic JSON transformation with no UI changes.

Before After
Delete $.items[2] from {"items": [1, 2, 1]} returns {"items": [2, 1]} Returns {"items": [1, 2]}

LLM Plugin Checklist

Not applicable: JSON Process is a non-LLM utility plugin.

Version

  • Bumped top-level version in manifest.yaml from 0.0.9 to 0.0.10; meta.version is unchanged.
  • dify_plugin>=0.3.0,<0.11.0 is declared in pyproject.toml and locked in uv.lock.

The existing declaration is dify_plugin>=0.10.2 and the lock resolves 0.10.2. Both production dependency files are unchanged by this focused bug fix; the existing declaration has no upper bound.

Testing

  • Local deployment
  • SaaS (cloud.dify.ai)

Tested in a fresh Windows CPython 3.12.14 environment created with uv sync --frozen for this plugin, using dify-plugin 0.10.2 and jsonpath-ng 1.12.0. pytest was supplied as test tooling without changing the production lock.

  • From tools/json_process: python -B -m pytest tests -q — 17 passed, none skipped. The same regression suite on unmodified main b4df0da gives 11 failed / 6 passed.
  • With the declared minimum jsonpath-ng 1.8.0 loaded separately: 17 passed.
  • Tests call the actual Tool.invoke() API and inspect real SDK messages. No daemon, services, external providers or production monkeypatching.
  • Ruff E4/E7/E9/F checks on the modified source and new test, new-test formatting, and git diff --check passed.

The SDK emits the same two warnings before and after (gevent SSL import order and Pydantic Config deprecation). Existing daemon-based integration tests and a deployed Dify instance were not run; no deployment result is claimed.

AI assistance

OpenAI Codex assisted with proactive issue discovery, duplicate checks, reproduction, the focused patch, tests and drafting. The source was an intentional contribution search, not a production incident. The patch and evidence were presented to the contributor, who approved submitting this change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] JSON Delete removes the first equal array value instead of the selected index

1 participant