Skip to content

Conversation

@Aman071106
Copy link
Contributor

PR Description

This PR adds robust JSON validation for the request body editor. It includes:

  1. Duplicate Key Detection: Identifies keys that appear multiple times in the same object scope (e.g., {"a": 1, "a": 2}). standard jsonDecode does not catch this, so a custom JsonUtils parser was implemented.
  2. Precise Error Reporting: Displays error messages with exact Line and Column numbers.
  3. Error Highlighting:
    • Adds a Status Card at the bottom of the editor when JSON is invalid.
    • Hover over the card to view full error details.
    • Tap the card to automatically select and highlight the error in the editor (jumps to the duplicate key or syntax error location).
  4. Debouncing: Validation runs 500ms after user stops typing to improve performance.

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • No, and this is why: please replace this line with details on why tests have not been included

Details:

  • Added test/utils/json_utils_test.dart to verify duplicate key detection, line counting, and offset calculation logic.
  • Manual verification steps included in walkthrough.md.

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

Example video

final_json_val_ex.mp4

@rakshaak29
Copy link

I tested the current behavior on macOS.
When POST body contains only whitespace, the request is sent and results in a 500 error.
This PR looks like it directly improves that UX by validating JSON before sending.
Happy to test this change locally if needed.

@Aman071106
Copy link
Contributor Author

@rakshaak29 Thanks for the review. Can you share a video?

@rakshaak29
Copy link

Thanks for the response!
I’ve attached a short screen recording demonstrating the behavior when
sending a POST request with invalid JSON in the body.
https://github.com/user-attachments/assets/bc4239d1-d5a7-4b35-954d-47dce7c720c9
Please let me know if you’d like me to test any other scenario.

@Aman071106
Copy link
Contributor Author

@rakshaak29 Thanks for the video , it would be extremely helpful for merging the pr, if you could add a after video also. This will confirm behaviour on macOS also.
@ashitaprasad @animator Please review this PR as changes are ready .

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.

Add validation for JSON request body

2 participants