NaviPath


License

License

GroupId

GroupId

tech.navicore
ArtifactId

ArtifactId

navipath_2.11
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

NaviPath
NaviPath
Project URL

Project URL

https://github.com/navicore/navipath
Project Organization

Project Organization

tech.navicore
Source Code Management

Source Code Management

https://github.com/navicore/NaviPath

Download navipath_2.11

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.fasterxml.jackson.core : jackson-databind jar 2.8.11.1
com.fasterxml.jackson.core : jackson-annotations jar 2.8.11
org.scala-lang.modules : scala-parser-combinators_2.11 jar 1.1.0

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.0.5

Project Modules

There are no modules declared in this project.

Build Status Codacy Badge

NaviPath

A lib for adding implicit JsonPath functions to Strings

Based on https://github.com/gatling/jsonpath. I've embedded the code from gatling instead of adding the maven binary dependency in order to support more scala versions via cross compile.

See http://goessner.net/articles/JsonPath/ for jsonpath documentation.

INSTALL

  • ongoing dev is for for scala 2.12+
  • if you use scala 2.11 - use version 2.1.0
// https://mvnrepository.com/artifact/tech.navicore/navipath
libraryDependencies += "tech.navicore" %% "navipath" % "4.0.1"

USAGE

See http://goessner.net/articles/JsonPath/ for JsonPath documentation.

DSL USAGE

Examples where "<json>" is a valid json string or parsed output from .asJson:

    import navicore.data.navipath.dsl.NaviPathSyntax._
    "<json>".query[String]("$.name")
    "<json>".query[Long]("$.widget.window.height")
    "<json>".query[List[String]]("$.stuff[*].name")
    "<json>".query[List[Int]]("$.stuff[*].value")

First match support:

    val jsonString = """{"name": "Ishmael"}"""
    import navicore.data.navipath.dsl.NaviPathSyntax._
    val result = jsonString.query[String]("$.name")
    result should be ('defined)
    result.fold()(assertResult("Ishmael"))

Multiple matches support:

    val jsonString = """{"stuff": [{"name": "Ishmael"}, {"name": "Mud"}]}"""
    import navicore.data.navipath.dsl.NaviPathSyntax._
    val results = jsonString.query[List[String]]("$.stuff[*].name")
    results.fold()(r => assert(r.head == "Ishmael"))
    results.fold()(r => assert(r(1) == "Mud"))

Parse once, query many times support:

    val jsonString = """{"stuff": [{"name": "Ishmael", "id": 1}, {"name": "Mud", "id": 2}]}"""
    import navicore.data.navipath.dsl.NaviPathSyntax._
    val parsedJson = jsonString.asJson
    val names = parsedJson.query[List[String]]("$.stuff[*].name")
    val ids = parsedJson.query[List[Int]]("$.stuff[*].value")
    ...
    ...

Versions

Version
2.1.0
2.0.0
1.0.0
0.2.0