Java json-sanitizer 修复不规范 JSON

JSON Java About 688 words

主要作用

  • 修复不规范JSON:自动补全/转换成标准JSON
  • 防止结构性XSS:去除</script>等危险组合。
  • 确保可安全嵌入HTML/XML:清除会破坏script/CDATA的内容。
  • 转换非标准JSON:支持单引号、注释、不规范数字等。

添加依赖

<dependency>
    <groupId>com.mikesamuel</groupId>
    <artifactId>json-sanitizer</artifactId>
    <version>1.2.3</version>
</dependency>

JsonSanitizer

static void main() {
    String json = """
            {
            "a": "123"456",
            "b": "789",
            }
            """;
    String wellFormedJson = JsonSanitizer.sanitize(json);
    System.out.println(wellFormedJson);
}

输出

{
"a": "123","456":",\n","b": "789"
}

GitHub

https://github.com/OWASP/json-sanitizer

https://github.com/OWASP/json-sanitizer/blob/master/docs/getting_started.md

Views: 6 · Posted: 2026-06-29

———         Thanks for Reading         ———

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓
Prev Post
Today In History
Browsing Refresh