Skip to content

refactor: centralise JSON parsing via json_utils.safe_json_loads#5858

Open
qizwiz wants to merge 10 commits into
google:mainfrom
qizwiz:fix/safe-json-loads
Open

refactor: centralise JSON parsing via json_utils.safe_json_loads#5858
qizwiz wants to merge 10 commits into
google:mainfrom
qizwiz:fix/safe-json-loads

Conversation

@qizwiz
Copy link
Copy Markdown

@qizwiz qizwiz commented May 26, 2026

Summary

Centralises all JSON parsing behind a single safe_json_loads(text, context) helper in utils/json_utils.py, following the same pattern as yaml_utils.py.

  • json.JSONDecodeError is always wrapped in ValueError with a human-readable message that includes the optional context label
  • 7 call sites updated across sessions/, tools/, flows/, memory/, agents/

Testing plan

  • tests/unittests/utils/test_json_utils.py (added in this PR): 13 unit tests covering well-formed objects/arrays/primitives, malformed input, error message format with and without context, __cause__ chain, and unicode content
  • Existing test suite: no behaviour change at call sites — safe_json_loads is a drop-in replacement; all existing tests continue to pass

@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented May 26, 2026

Response from ADK Triaging Agent

Hello @qizwiz, thank you for creating this PR!

We appreciate your contribution to centralising JSON error handling. However, to help us review your PR more efficiently, please ensure it aligns with our Contribution Guidelines. Specifically, we noticed the following items are missing:

  1. Testing Plan: Please include a testing plan section in your PR description to describe how you verified (or plan to verify) these changes.
  2. Unit Tests: Since this PR introduces a new utility (json_utils.py) and refactors several parsing call sites, please add or update unit tests under the tests/unittests/ directory (for example, testing safe_json_loads behavior with well-formed and malformed inputs) to prevent regressions.

Providing this information and coverage will save time for the PR review and ensure code quality. Thank you!

Covers: well-formed objects/arrays/primitives, malformed input raises
ValueError, error message includes context label, __cause__ is
JSONDecodeError, unicode content.
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.

2 participants