AssertJ for JSON

A set of AssertJ assertions for JSON validation.

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.revinate
ArtifactId

ArtifactId

assertj-json
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

AssertJ for JSON
A set of AssertJ assertions for JSON validation.
Project URL

Project URL

https://github.com/revinate/assertj-json
Source Code Management

Source Code Management

https://github.com/revinate/assertj-json

Download assertj-json

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-core jar 2.6.3
com.jayway.jsonpath : json-path jar 2.4.0
com.fasterxml.jackson.core : jackson-databind jar 2.6.3
org.assertj : assertj-core jar 3.8.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

AssertJ Json

Build Status Maven Central Javadoc codecov.io Codacy Badge

A set of AssertJ assertions to validate JSON.

JsonPath

Use JsonPathAssert to extract values using JsonPath and validate as a Java string, integer or list.

Example:

DocumentContext ctx = JsonPath.parse("{\"value\":\"a text value\"}");

assertThat(ctx).jsonPathAsString("$.value").contains("text").endsWith("value");

Runtime configuration

JsonPathAssert uses JayWay JsonPath under the covers. In order to execute more complex extractions like array of strings to List<String> you need to have Jackson or Gson in your classpath and configure JsonPath to use one of them.

One option is to execute the following snipped of code in a @BeforeClass method in your test class.

Configuration.setDefaults(new Configuration.Defaults() {
    private final JsonProvider jsonProvider = new JacksonJsonProvider();
    private final MappingProvider mappingProvider = new JacksonMappingProvider();

    @Override
    public JsonProvider jsonProvider() {
        return jsonProvider;
    }

    @Override
    public MappingProvider mappingProvider() {
        return mappingProvider;
    }

    @Override
    public Set<Option> options() {
        return EnumSet.noneOf(Option.class);
    }
});
com.revinate

Revinate, Inc.

Versions

Version
1.2.0
1.1.0
1.0.1
1.0.0