Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
json-sanitizer — Given JSON-like content, The JSON Sanitizer converts it to valid JSON. | Kitploit
Tools/GitHubGitHub/owasp/json-sanitizer
General Purpose UtilitiesStatic AnalysisEncryption/Decryption ToolsVulnerability AnalysisCode AnalysisWeb Security
GitHubowasp/json-sanitizer

json-sanitizer

Given JSON-like content, The JSON Sanitizer converts it to valid JSON.

View Repository
21955743 days agoReviewed by Kitploit
Share

OWASP JSON Sanitizer

CI

Converts JSON-like text into valid JSON, with escaping for HTML script elements and XML CDATA sections. It repairs input rather than rejecting malformed JSON; use a strict parser when invalid input must be rejected.

Requires Java 8 or later, with no runtime dependencies.

<dependency>
  <groupId>org.owasp.json-sanitizer</groupId>
  <artifactId>json-sanitizer</artifactId>
  <version>1.3.0</version>
</dependency>
import com.google.json.JsonSanitizer;

String json = JsonSanitizer.sanitize("{name:'Ada',}");
// {"name":"Ada"}

Getting started and migration · Changelog · Security policy · Contact

Input

The sanitizer repairs common JavaScript-like syntax without executing it. It is not a JavaScript evaluator.

ConstructPolicy
'...'Single quoted strings are converted to JSON strings.
\xABHex escapes are converted to JSON unicode escapes.
\012Octal escapes are converted to JSON unicode escapes.
0xABHex integer literals are converted to JSON decimal numbers.
012Octal integer literals are converted to JSON decimal numbers.
+.5Decimal numbers are coerced to JSON's stricter format.
[0,,2]Elisions in arrays are filled with null.
[1,2,3,]Trailing commas are removed.
{foo:"bar"}Unquoted property names are quoted.
//commentsJS style line and block comments are removed.
(...)Grouping parentheses are removed.

The sanitizer fixes missing punctuation, end quotes, and mismatched or missing close brackets. If an input contains only white-space then the valid JSON string null is substituted.

Output

The output has these guarantees (also documented in the JsonSanitizer Javadoc):

  1. It is exactly one JSON value as defined by RFC 8259. Anything after the first complete value, a top-level comma or an unmatched close bracket is dropped: [1]],alert(1) becomes [1].
  2. It does not contain <script, </script, <!-- or -->, in any case, so it can be embedded in an HTML script element without further encoding.
  3. It does not contain ]]>, so it can be embedded in an XML CDATA section without further encoding. (<![CDATA[ itself is not escaped.)
  4. JSON.parse accepts it. It is also a JavaScript expression that eval can run after it is wrapped in parentheses, except that an object repeating the key __proto__ is a syntax error there. No string contains a raw U+2028 or U+2029.
  5. Inside strings, U+0000 to U+001F, lone UTF-16 surrogates, U+2028, U+2029, U+FFFE and U+FFFF use JSON escapes (short forms such as \t and \n, or \uXXXX); between tokens only space, tab, line feed and carriage return appear. Other characters, U+007F to U+009F included, appear as they are, so the output is valid Unicode and allowed in XML 1.0. An escaped lone surrogate is valid RFC 8259 but not I-JSON.
  6. Sanitizing it again with the same maximumNestingDepth returns it unchanged (through a Reader or InputStream overload, with a maximumInputLength at least as long as the output).

Brackets nest at most 64 levels deep by default (DEFAULT_NESTING_DEPTH), or as set by a maximumNestingDepth parameter, which is clamped to 1 to 4096; a deeper array or object is replaced by null. Hex and octal literals of more than 1024 significant digits become 1e999, JavaScript's Infinity. Numeric object keys are converted to a string form textually: an exponent outside the double range is kept ({1e400:0} becomes {"1e+400":0}, not "Infinity"), and one beyond the int range is kept as written ({1e2147483648:0} becomes {"1e2147483648":0}), so keys of equal value can differ. The Reader and InputStream overloads accept at most 4 Mi chars (DEFAULT_MAXIMUM_INPUT_LENGTH) unless given a maximumInputLength. The library runs on Java 8 and later.

Requirements and limits

  • Java 8 or later; automatic module name com.google.json.
  • String and CharSequence input takes O(n) time in UTF-16 code units. Results are immutable strings; an already-safe String may be reused. These overloads have no input-length limit, so callers must bound untrusted input themselves.
  • Reader and UTF-8 InputStream overloads buffer the whole input. The default limit is 4,194,304 UTF-16 code units, configurable with maximumInputLength. Exceeding it throws IOException before any output is written. The Reader loop may read up to 8,192 characters beyond the limit; UTF-8 decoding can read additional bytes ahead. This is not a byte or network-request limit.
  • Output can expand to roughly six times the input length. Allow heap space for input, output and temporary buffers; the input limit is not a heap limit.
  • Malformed UTF-8 decodes to U+FFFD. Streams are not closed; the OutputStream overload flushes its output.
  • Nullness annotations use JSpecify in provided scope. Add org.jspecify:jspecify:1.0.1 to your build if your analysis tools need them.

Security

Parse output with JSON.parse or a JSON parser. Sanitization does not validate business rules, authorize actions, or make parsed values safe for innerHTML, SQL, shell commands, or later JavaScript execution. The embedding guarantees above do not apply to HTML attributes or arbitrary output contexts.

EvalMinifier is deprecated. It produces a JavaScript expression requiring execution, rather than JSON for JSON.parse; a strict Content Security Policy blocks eval. Keep it only for existing integrations.

Development

Build with JDK 17 or later and Maven 3.6.3 or later in the 3.x series:

mvn -B -ntp clean verify

CI builds on JDK 21 and tests on Java 8, 11, 17, 21 and 25, with Jazzer fuzzing and an OSS-Fuzz build check. See MODELS.md for model-assisted review and the release guide for publishing. The modernization archive preserves historical decisions and evidence; it is not current setup guidance.

Download Tool

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    565
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    478
  • 3

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    383
  • 4

    redforge

    cybersecurity91/redforge

    Browser-side red team toolkit with 102 offline tools for recon, payload generation, credential attacks, crypto, encoding and engagement reporting.

    327
  • 5

    estorides

    grisuno/estorides

    Aggregates 99+ free OSINT sources in parallel, resolves entities into a knowledge graph, and exports STIX 2.1, MISP, or GraphML with LLM-assisted analysis.

    258
  • 6

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    The system of action for AI-native cybersecurity—where intent becomes governed execution, evidence becomes operational memory, and every operation improves the next.

    256

Explore all tools

Browse our collection of tools

View all tools →