feat: Add JSON output format for machine-readable diffs (#60)#70
Merged
Conversation
Implements issue #60 - JSON output format for AI agents and automation tools. Features: - New output_json() method with optional pretty-printing - Hybrid approach: both character and token positions - Complete diff representation including equal operations - Exposed token lists for full transparency - Comprehensive JSON Schema specification The JSON output includes: - Source and test texts - Token arrays showing text parsing - Changes array with all diff operations - Statistics about changes Each change provides: - Type (equal/insert/delete/replace) - Text content - Character positions for direct string access - Token positions for internal representation Testing: - 16 comprehensive test cases - All 46 tests pass - 96% code coverage on redlines.py Files: - redlines/redlines.py: Added output_json() method - redlines/json_schema.json: JSON Schema Draft 7 spec - tests/test_json_output.py: Complete test suite 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add explicit type annotations to resolve mypy errors in output_json() method. The change variable now has explicit type hint dict[str, t.Any] to handle None values in position fields for delete/insert operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds explicit type hint dict[str, int] to resolve mypy strict mode error. Required for Python 3.10 compatibility with strict type checking. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds JSON output format to make diff results easily parseable by AI agents and automation tools.
Closes #60
Changes
New API Method
JSON Output Structure
The JSON includes complete diff information:
Hybrid Position System
Each change provides both position types for maximum flexibility:
This design allows users to choose the most convenient approach for their use case while maintaining full transparency into how Redlines processes
the text.
Example Output
Design Decisions
Files Changed
Testing
Backwards Compatibility
This is a purely additive change - no existing functionality is modified. All existing tests continue to pass.