Class/Object

com.rojoma.json.v3.jpath

JPath

Related Docs: object JPath | package jpath

Permalink

class JPath extends AnyRef

A high-level interface for walking down a tree defined by a com.rojoma.json.v3.ast.JValue, returning a set of sub-values that match a path defined by a series of steps.

Example:
  1. val v = JsonReader.fromString("""
      {
         "array": [1,2,3],
         "object": {
           "France" : [ "Paris", "Lyon", "Bordeaux" ],
           "Germany" : [ "Berlin", "Munich", "Leipzig" ],
           "Italy" : [ "Rome", "Florence", "Milan" ]
         }
      }
    """)
    def contains(z: JsonZipper, s: String) =
      z.asArray.map(_.value.toSeq.contains(JString(s))).getOrElse(false)
    JPath(v).down("array").finish
       // --> Stream(JArray(JNumber(1), JNumber(2), JNumber(3)))
    JPath(v).down("object").*.downFirst.finish
       // --> Stream(JString("Paris"), JString("Berlin"), JString("Rome"))
    JPath(v).*.down("France").downFirst.finish
       // --> Stream(JString("Paris"))
    JPath(v).**.downFirst.finish
      // --> Stream(JNumber(1), JString("Paris"), JString("Berlin"), JString("Rome"))
    JPath(v).*.having(_.*.where(contains(_, "Lyon"))).finish
      // --> Stream(JObject("France" -> ..., "Germany" -> ..., "Italy" -> ...))
    JPath(v).*.*.where(contains(_, "Lyon")).finish
      // --> Stream(JArray(JString("Paris"), JString("Lyon"), JString("Bordeaux")))
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JPath
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JPath(input: JValue)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def *: JPath

    Permalink

    Go down into all children, whether fields or array elements.

    Go down into all children, whether fields or array elements. If a current point is not a com.rojoma.json.v3.ast.JObject or com.rojoma.json.v3.ast.JArray, it is dropped.

  4. def **: JPath

    Permalink

    Go down (as by *) and then add every descendant of the current points to the set of points (as by rec).

  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def down(target: Int): JPath

    Permalink

    Go down into the given index.

    Go down into the given index. If a current point is not a com.rojoma.json.v3.ast.JArray, or does not contain the index, it is dropped.

  9. def down(target: String): JPath

    Permalink

    Go down into the named field.

    Go down into the named field. If a current point is not a com.rojoma.json.v3.ast.JObject, or does not contain the field, it is dropped.

  10. def downFirst: JPath

    Permalink

    Go down into the first child of an array.

    Go down into the first child of an array. If a current point is not a com.rojoma.json.v3.ast.JArray, it is dropped.

  11. def downLast: JPath

    Permalink

    Go down into the last child of an array.

    Go down into the last child of an array. If a current point is not a com.rojoma.json.v3.ast.JArray, it is dropped.

  12. def downWhere(pred: (JsonZipper) ⇒ Boolean): JPath

    Permalink

    Go down into all children (as by *) and then filter by a predicate (as by where).

  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. def finish: Stream[JValue]

    Permalink

    Produce a Stream of com.rojoma.json.v3.ast.JValues, one for each current point.

  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. def having(pred: (JPath) ⇒ JPath): JPath

    Permalink

    Filter the current set of points by applying another JPath operation to them and keeping only the ones that ended up with a non-empty set of results.

    Filter the current set of points by applying another JPath operation to them and keeping only the ones that ended up with a non-empty set of results.

    This is basically mark-and-return. E.g.,

    x.having(_.down("foo").*.where(isNumberGreaterThan(5)))

    is the same as:

    x.down("foo").*.where(isNumberGreaterThan(5)).up.up

    but also works if one of the inner steps is "rec", where no fixed number of final up steps would suffice.

  20. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  21. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. def next: JPath

    Permalink

    Move to the next sibling.

    Move to the next sibling. Any points that were at the end already, or which were not children of com.rojoma.json.v3.ast.JArrays, will be dropped.

  23. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. def prev: JPath

    Permalink

    Move to the previous sibling.

    Move to the previous sibling. Any points that were at the start already, or which were not children of com.rojoma.json.v3.ast.JArrays, will be dropped.

  26. def rec: JPath

    Permalink

    Add every descendant of the current points to the set of points.

  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  28. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  29. def up: JPath

    Permalink

    Go up to the parents of the current points.

    Go up to the parents of the current points. Any that were already at the top of the tree will be dropped.

  30. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. def where(pred: (JsonZipper) ⇒ Boolean): JPath

    Permalink

    Filter the set of current points by a predicate.

Inherited from AnyRef

Inherited from Any

Ungrouped