FEAT: Add JsonStringConverter for JSON-safe string conversion (#454)#1347
Merged
romanlutz merged 5 commits intoAzure:mainfrom Feb 6, 2026
Merged
Conversation
Contributor
Author
@microsoft-github-policy-service agree |
Add JsonStringConverter class that escapes special characters for JSON embedding Add comprehensive unit tests with pytest fixture following PyRIT best practices Update init.py to export JsonStringConverter Update HTTP target example to demonstrate JSON string converter usage All tests pass and follow PyRIT style guide
7c3a781 to
66663b6
Compare
romanlutz
approved these changes
Feb 4, 2026
- Add JsonStringConverter to doc/api.rst API documentation - Add JsonStringConverter example to converter notebook - Fix import ordering in test_json_string_converter.py (ruff) - Update Unicode test to use Tamil script - Fixes GitHub Actions failures for missing documentation
Contributor
Author
|
Pushed updates to address the earlier CI failures. cc: @romanlutz |
romanlutz
reviewed
Feb 4, 2026
…des/json_string_converter
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.
Description
Adds a new
JsonStringConverterthat usesjson.dumps()to properly escape strings for JSON embedding, addressing issue #454.Changes:
JsonStringConverterclass that escapes special characters for JSON embedding__init__.pyto exportJsonStringConverterUse case: When sending prompts to HTTP targets expecting JSON payloads, strings need proper escaping. Previously this required
SearchReplaceConverter(pattern=r"(?! )\s", replace="")which only stripped whitespace. The new converter handles all JSON escaping correctly (quotes, newlines, tabs, backslashes, unicode).Example:
Closes #454
Tests and Documentation
tests/unit/converter/test_json_string_converter.pycovering:uv run pytest tests/unit/converter/test_json_string_converter.py -vdoc/code/targets/10_http_target.pyand10_http_target.ipynbto useJsonStringConverterinstead ofSearchReplaceConverter