Overview
Introduction
Most JSON tools assume the input is at least trying to be valid, but testing error handling requires the opposite: input that's realistically broken in the ways real-world JSON actually breaks.
This tool takes valid JSON and deliberately damages it with random, realistic syntax mutations.
What Is JSON Error Injector?
A corruption generator that first confirms your input is valid JSON, then re-serializes it and applies a chosen number of random textual mutations drawn from five mutation types.
The output is meant to often be invalid JSON, since it exists to exercise error paths in other tools and code.
How JSON Error Injector Works
The input is parsed and re-serialized with JSON.stringify to get a clean baseline, then a set number of mutations (1 for light, 3 for medium, 6 for heavy) are applied one at a time, each randomly choosing from the five mutation types and skipping any that aren't applicable to the current text.
Because mutations are chosen randomly and applied sequentially, the same input and intensity can produce a different corrupted result on every run.
When To Use JSON Error Injector
Use it when you're writing tests for a JSON parser, form validator, or error-handling UI and need realistic broken sample data.
It's also useful for demoing how a tool like Fix JSON or JSON Validator handles malformed input.
Often used alongside JSON Fixer, JSON Validator and JSON Formatter & Beautifier.
Features
Advantages
- Generates realistically broken JSON rather than arbitrary garbage text.
- Configurable intensity lets you dial in how badly damaged the output is.
- Guarantees the starting point was valid JSON, so any breakage is attributable to the tool's mutations, not pre-existing errors.
Limitations
- Mutations are randomized, so the exact corruption produced isn't reproducible or user-controllable beyond the intensity level.
- There's no guarantee the output is invalid JSON; a mutation like duplicating a whitespace character can occasionally leave valid JSON valid.
Examples
Best Practices & Notes
Best Practices
- Use light intensity when you want a subtly broken document that might trip up a lenient parser; use heavy for stress-testing.
- Run the tool multiple times on the same input if you need a variety of different broken samples for a test suite.
- Pair with JSON Validator to confirm the corrupted output is actually invalid before using it as a negative test case.
Developer Notes
Mutation selection shuffles the list of mutator functions and tries them in order per mutation, skipping any that return null (because, for example, there's no comma left to delete), which keeps the tool from silently doing nothing when a chosen mutation type isn't applicable to the current text.
JSON Error Injector Use Cases
- Generating negative test cases for a JSON parser or validator
- Demoing how an error-handling UI displays malformed JSON
- Producing sample broken input for a tutorial or documentation about error handling
Common Mistakes
- Expecting deterministic output; the mutations are randomized, so re-running with the same input gives a different result.
- Assuming the output is always invalid JSON; it's usually broken but this isn't strictly guaranteed for every mutation combination.
- Feeding it already-invalid JSON, the tool requires valid JSON as a starting point so it has a clean baseline to corrupt.
Tips
- Use Fix JSON afterward to see how well a best-effort repair tool recovers from the specific damage generated here.
- Try all three intensity levels on the same input to get a feel for how much damage each level actually causes.