snodge

A small, extensible Java library to randomly mutate JSON documents. Useful for fuzz testing.

License

License

GroupId

GroupId

com.natpryce
ArtifactId

ArtifactId

snodge
Last Version

Last Version

3.7.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

snodge
A small, extensible Java library to randomly mutate JSON documents. Useful for fuzz testing.
Project URL

Project URL

https://github.com/npryce/snodge
Source Code Management

Source Code Management

https://github.com/npryce/snodge

Download snodge

How to add to project

<!-- https://jarcasting.com/artifacts/com.natpryce/snodge/ -->
<dependency>
    <groupId>com.natpryce</groupId>
    <artifactId>snodge</artifactId>
    <version>3.7.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.natpryce/snodge/
implementation 'com.natpryce:snodge:3.7.0.0'
// https://jarcasting.com/artifacts/com.natpryce/snodge/
implementation ("com.natpryce:snodge:3.7.0.0")
'com.natpryce:snodge:jar:3.7.0.0'
<dependency org="com.natpryce" name="snodge" rev="3.7.0.0">
  <artifact name="snodge" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.natpryce', module='snodge', version='3.7.0.0')
)
libraryDependencies += "com.natpryce" % "snodge" % "3.7.0.0"
[com.natpryce/snodge "3.7.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1

Project Modules

There are no modules declared in this project.

Snodge

Kotlin Build Status Maven Central npm

A small, extensible Kotlin library to randomly mutate JSON & XML documents, text and binary data. Useful for fuzz testing.

Examples of things you can test by mutating known good data:

  • unexpected structures will not make your application code throw unchecked exceptions
  • your application code ignores additional properties
  • your application code does not throw unchecked exceptions when parsing values from text properties
  • your application does not instantiate arbitrary classes named in data (a potential security risk)
  • your application copes with invalid Unicode encoding of text
  • and much, much more!

See an interactive demonstration.

In a Nutshell

Add a dependency on Snodge (replace <version> with the version of Snodge you wish to use):

testImplementation 'com.natpryce:snodge:<version>'

For the JVM platform, add an implementation of the JSR-374 JSONP API, such as:

testRuntimeOnly 'org.glassfish:javax.json:1.1'

Import the library:

import com.natpryce.snodge.mutants
import com.natpryce.snodge.json.defaultJsonMutagens

Output 10 random mutations of the JSON document:

val random = Random()
val originalJson = "{\"x\": \"hello\", \"y\": [1,2,3]}"

random.mutants(defaultJsonMutagens().forStrings(), 10, originalJson)
    .forEach(::println)

Example output:

{"x":"hello","y":[1,2,3,null]}
{"y":[1,2,3],"x":{}}
{"x":"hello","y":[2,3]}
{"x":"hello","y":[{},2,3]}
{"x":"hello"}
{"x":"hello","y":[1,2,{}]}
{"x":"hello","y":[1,null,3]}
{"y":[1,2,3],"x":"hello"}
{"y":[1,2,3],"x":"a string"}
{"x":"hello","y":[99,2,3]}

API Adapters

On the JVM, Snodge can mutate the JSON object models of the Jackson, GSON & JSR-374 JSONP and Argo APIs, XML DOM, and JSON and XML serialised as text and binary.

On JavaScript, Snodge can mutate XML as DOM Documents, and XML and JSON as text.

For more information, continue reading the documentation.

Other versions

The Kotlin library is version 3.x.x.x.

Previous versions:

  • Version 2.x.x.x (java8 branch) is for Java 8, and uses streams and Java 8 function types
  • Version 1.x.x.x (java7 branch) is for Java 7 and depends on Guava

Download from Maven Central

Download from NPM

Versions

Version
3.7.0.0
3.7.0.0-RC1
3.6.2.0
3.6.1.0
3.6.0.0
3.5.1.0
3.5.0.0
3.4.0.0
3.3.2.0
3.3.1.0
3.3.0.1
3.3.0.0
3.2.0.0
3.1.0.1
3.1.0.0
3.0.0.3
2.1.2.2
2.1.2.1
2.1.2.0
2.1.1.0
2.1.0.0
1.3.4.2
1.3.4.1
1.3.4.0
1.3.3.0
1.3.2.0
1.3.1.1
1.3.0.2