Skip to content

jCalamari/play-jsonpath

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONPath library for Play

This library enables JSONPath queries on the Play JsValue.

Explanation of JSONPath can be found here: http://goessner.net/articles/JsonPath/

This version should work with Play apps running 2.1.x through 2.3.x (update for Play 2.4.x is pending).

Install

libraryDependencies += "com.josephpconley" %% "play-jsonpath" % "1.1"

Example Usage

val json = Json.parse("""
{
 "id": 1,
 "name": "Joe",
 "tags": ["programmer", "husband", "father", "golfer"],
 "address": [
    {"id": 2, "street": "123 Main St.", "city": "Springfield", "state": "PA"},
    {"id": 3, "street": "456 Main St.", "city": "Sea Isle City", "state": "NJ", "beach": true}
 ]
}
"""

import com.josephpconley.jsonpath.JSONPath

JSONPath.query("$.id", json)                    //JsNumber(1)
JSONPath.query("$..id", json)                   //JsArray(JsNumber(1), JsNumber(2), JsNumber(3))
JSONPath.query("$.address[*].city", json)       //JsArray(JsString("Springfield"), JsString("Sea Isle City"))
JSONPath.query("$.address[?(@.beach)]", json)   //JsArray(JsObject(Seq("id" -> JsNumber(3), "street" -> JsString("456 Main St."), "city" -> JsString("Sea Isle City"), "state" -> JsString("NJ"), "beach" -> JsBoolean(true)))

Blog post

You can read more about the library here

About

JSONPath library to complement Play's json library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 100.0%