com.rojoma.json.v3.jpath

JPath

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
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JPath(input: JValue)

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def *: JPath

    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.

  5. def **: JPath

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

  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

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

    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.

  11. def down(target: String): JPath

    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.

  12. def downFirst: JPath

    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.

  13. def downLast: JPath

    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.

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

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

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

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

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

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

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

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

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

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

    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.

  22. final def isInstanceOf[T0]: Boolean

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

    Definition Classes
    AnyRef
  24. def next: JPath

    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.

  25. final def notify(): Unit

    Definition Classes
    AnyRef
  26. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  27. def prev: JPath

    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.

  28. def rec: JPath

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

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

    Definition Classes
    AnyRef
  30. def toString(): String

    Definition Classes
    AnyRef → Any
  31. def up: JPath

    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.

  32. final def wait(): Unit

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

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

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

    Filter the set of current points by a predicate.

Inherited from AnyRef

Inherited from Any

Ungrouped