Skip to content
Scalatest matchers for Json with appropriate equality and descriptive error messages.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
circe
json4s bump json4s to 0.0.3-snapshot Jan 26, 2018
jsonassert set jsonassort 0.0.4-snapshot Jan 27, 2018
play-json
project
.gitignore
.travis.yml
LICENSE
build.sbt
readme.md

readme.md

Scalatest-json

Build Status

Scalatest matchers for Json with appropriate equality and descriptive error messages.

install

Add the dependency you want

libraryDependencies += "com.stephenn" %% "scalatest-json-jsonassert" % "0.0.3"
libraryDependencies += "com.stephenn" %% "scalatest-json4s" % "0.0.2"
libraryDependencies += "com.stephenn" %% "scalatest-play-json" % "0.0.1"
libraryDependencies += "com.stephenn" %% "scalatest-circe" % "0.0.1"

usage

Your scalatest spec should extend or import JsonMatchers

class ExampleSpec extends FunSpec with Matchers with JsonMatchers {

  describe("JsonMatchers usage") {
    it("should pass matching json with different spacing and order") {
      val input = """
        |{
        | "some": "valid json",
        | "with": ["json", "content"]
        |}
      """.stripMargin

      val expected = """
                    |{
                    | "with": ["json", "content"],
                    |     "some":   "valid json"
                    |}
                  """.stripMargin

      input should matchJson(expected)
    }

    it("should fail on slightly different json explaining why") {
      val input = """
                    |{
                    | "someField": "valid json"
                    |}
                  """.stripMargin

      val expected = """
                       |{
                       | "someField": "different json"
                       |}
                     """.stripMargin

      input should matchJson(expected)
//
//      Fails
//
//      Json did not match {
//      "someField": "valid json"
//      } did not match {
//      "someField": "different json"
//      }
//
//      Json Diff:
//        someField
//      Expected: different json
//        got: valid json

    }
  }
}

Publishing

  1. bump version in module to non snaphsot
  2. commit and tag git tag json4s-0.0.1 git push --tags
  3. sbt +json4s/publishSigned
  4. sbt sonatypeReleaseAll
  5. bump version to snapshot
You can’t perform that action at this time.