Repository navigation
Stop escaping Unicode characters unnecessarily in relational JSON - #36166
Draft
AndriySvyryd with Copilot wants to merge 3 commits into
Draft
AndriySvyryd with Copilot wants to merge 3 commits into
AndriySvyryd with Copilot wants to merge 3 commits into
Conversation
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] When updating JSON columns, Chinese characters will be escaped twice.
Fix double escaping of Chinese characters in JSON columns during updates
May 31, 2025
Member
|
@copilot Call |
Contributor
Author
Done. I've executed both Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
…Context switch Co-authored-by: AndriySvyryd <[email protected]>
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
roji
force-pushed
the
main
branch
2 times, most recently
from
January 13, 2026 17:46
249ae47 to
6b86657
Compare
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.
Issue
When updating JSON columns in SQL Server, Chinese characters (and other Unicode characters) were being double-escaped, causing them to appear as Unicode escape sequences instead of the actual characters. For example, "测试2" would become "\u6D4B\u8BD52" after an update operation.
Root Cause
The issue was in the
SqlServerOwnedJsonTypeMapping.GenerateNonNullSqlLiteralmethod, which was callingJsonSerializer.Serialize()on all values, including those that were already JSON strings from theCollectionToJsonStringConverter. This caused JSON strings to be serialized twice, leading to double escaping of Unicode characters.Solution
Modified the
GenerateNonNullSqlLiteralmethod to check if the input value is already a string (indicating it's already serialized JSON) and use it directly instead of serializing it again:This surgical fix:
Testing
Added a comprehensive test case
Edit_single_property_with_chinese_charactersthat verifies:Fixes #32152.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.