com.rojoma.json.jpath

JPath

class JPath extends AnyRef

A high-level interface for walking down a tree defined by a 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. Hide All
  2. Show all
  1. JPath
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new JPath (input: JValue)

Value Members

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

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

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

    Attributes
    final
    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 JObject or 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. def == (arg0: AnyRef): Boolean

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

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

    Attributes
    final
    Definition Classes
    Any
  9. def clone (): AnyRef

    Attributes
    protected[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 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 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 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 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. def eq (arg0: AnyRef): Boolean

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

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

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

    Produce a Stream of JValues, one for each current point.

  19. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef
  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. def isInstanceOf [T0] : Boolean

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

    Attributes
    final
    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.ast.JArrayss, will be dropped.

  25. def notify (): Unit

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

    Attributes
    final
    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.ast.JArrayss, will be dropped.

  28. def rec : JPath

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

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

    Attributes
    final
    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. def wait (): Unit

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

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

    Attributes
    final
    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