Packages

sealed abstract class JValue extends Diffable

The base type for all things that represent distinct JSON entities in the AST.

Most members of the AST will extend this class. The one exception is JField which does not extend this class because it really can't properly exist as a first-class citizen of JSON.

Linear Supertypes
Diffable, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. JValue
  2. Diffable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Values
  2. final class WithFilter extends AnyRef

Abstract Value Members

  1. abstract def values: Values

    Return a representation of the values in this JValue in a native Scala structure.

    Return a representation of the values in this JValue in a native Scala structure.

    For example, you might invoke this on a JObject to have its fields returned as a Map.

    scala> JObject(JField("name", JString("joe")) :: Nil).values
    res0: scala.collection.immutable.Map[String,Any] = Map(name -> joe)

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def ++(other: JValue): JValue

    Concatenate this JValue with another JValue.

    Concatenate this JValue with another JValue.

    Example:

    > JArray(JInt(1) :: JInt(2) :: Nil) ++ JArray(JInt(3) :: Nil)
    res0: JArray(List(JInt(1), JInt(2), JInt(3)))
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def \[A <: JValue](clazz: Class[A]): List[\.A.Values]

    Find immediate children of this JValue that match a specific JValue subclass.

    Find immediate children of this JValue that match a specific JValue subclass.

    This methid will search a JObject or JArray for values of a specific type and return a List of those values if they any are found.

    So given some JSON like so:

    [
      {
        "thinga":1,
        "thingb":"bacon"
      },{
        "thingc":3,
        "thingd":"Wakka"
      },{
        "thinge":{
          "thingf":4
        },
        "thingg":true
      }
    ]

    You would use this method like so:

    scala> json \ classOf[JInt]
    res0: List[net.liftweb.json.JInt#Values] = List(1, 3)

    This method does require that whatever type you're searching for is subtype of JValue.

  6. def \(nameToFind: String): JValue

    An XPath-like expression to find a child of a JObject or a JArray of JObject by name.

    An XPath-like expression to find a child of a JObject or a JArray of JObject by name. If you call this method on anything other than a JObject or JArray of JObjects you'll get a JNothing.

    This method is most useful if you have an object that you need to dig into in order to retrieve a specific value. So, let's say that you had a JSON object that looked something like this:

    {
      "name": "Joe",
      "profession": "Software Engineer",
      "catchphrase": {
        "name": "Alabama Cheer",
        "value": "Roll tide"
      }
    }

    If for some reason you're interested in taking a look at Joe's catchphrase, you can query it using the \ method to find it like so:

    Example:

    scala> json \ "catchphrase"
    res0: JValue = JObject(List(JField("name", JString("Alabama Cheer")), JField("value", JString("Roll tide"))))

    Likewise, if you wanted to find Joe's name you could do the following:

    scala> json \ "name"
    res0: JValue = JString("Joe")

    The result could be any subclass of JValue. In the event that the JValue you're operating on is actually an array of objects, you'll get back a JArray of the result of executing \ on each object in the array. In the event nothing is found, you'll get a JNothing.

  7. def \\[A <: JValue](clazz: Class[A]): List[\\.A.Values]

    Find all descendants of this JValue that match a specific JValue subclass.

    Find all descendants of this JValue that match a specific JValue subclass.

    Unlike its cousin \, this method will recurse down into all children looking for type matches searching a JObject or JArray for values of a specific type and return a List of those values if they are found.

    So given some JSON like so:

    [
      {
        "thinga":1,
        "thingb":"bacon"
      },{
        "thingc":3,
        "thingd":"Wakka"
      },{
        "thinge":{
          "thingf":4
        },
        "thingg":true
      }
    ]

    You would use this method like so:

    scala> json \\ classOf[JInt]
    res0: List[net.liftweb.json.JInt#Values] = List(1, 3, 4)
  8. def \\(nameToFind: String): JObject

    Find all children of a JObject with the matching name, returning an empty JObject if no matches are found.

    Find all children of a JObject with the matching name, returning an empty JObject if no matches are found.

    For example given this example JSON:

    {
      "name": "Joe",
      "profession": "Software Engineer",
      "catchphrase": {
        "name": "Alabama Cheer",
        "value": "Roll tide"
      }
    }

    We might do the following:

    scala> json \\ "name"
    res2: JValue = JObject(List(JField(name,JString(Joe)), JField(name,JString(Alabama Cheer))))
  9. def apply(i: Int): JValue

    Return the element in the i-th position from a JArray.

    Return the element in the i-th position from a JArray. Will return JNothing when invoked on any other kind of JValue.

    For example:

    scala> val array = JArray(JInt(1) :: JInt(2) :: Nil)
    array: net.liftweb.json.JsonAST.JArray = JArray(List(JInt(1), JInt(2)))
    
    scala> array(1)
    res0: net.liftweb.json.JsonAST.JValue = JInt(2)
  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def children: List[JValue]

    Return direct child elements of this JValue, if this JValue is a JObject or JArray.

    Return direct child elements of this JValue, if this JValue is a JObject or JArray.

    This method is useful for getting all the values of a JObject or JArray and will return them as a List[JValue]. If the JValue you invoke this method on is not a JObject or JArray you will instead get Nil.

    Example:

    > JArray(JInt(1) :: JInt(2) :: Nil).children
    List(JInt(1), JInt(2))
    returns

    Direct children of this JValue if it is a JObject or JArray, or JNothing otherwise.

  12. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  13. def diff(other: json.JValue): Diff

    Return a diff.

    Return a diff.

    Definition Classes
    Diffable
    See also

    net.liftweb.json.Diff#diff

  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def extract[A](implicit formats: Formats, mf: Manifest[A]): A

    Extract a value into a concrete Scala instance from its JValue representation.

    Extract a value into a concrete Scala instance from its JValue representation.

    Value can be:

    • a case class
    • a primitive (String, Boolean, Date, etc.)>
    • any type which has a configured custom deserializer
    • a supported collection type of any of the above (List, Seq, Map[String, _], Set)

    Example:

    > case class Person(name: String)
    > JObject(JField("name", JString("joe")) :: Nil).extract[Person]
    res0: Person("joe")
  17. def extractOpt[A](implicit formats: Formats, mf: Manifest[A]): Option[A]

    Optionally extract a value into a concrete Scala instance from its JValue representation.

    Optionally extract a value into a concrete Scala instance from its JValue representation.

    This method will attempt to extract a concrete Scala instance of type A, but if it fails it will return a scala.None instead of throwing an exception as extract would.

    Value can be:

    • a case class
    • a primitive (String, Boolean, Date, etc.)>
    • any type which has a configured custom deserializer
    • a supported collection type of any of the above (List, Seq, Map[String, _], Set)

    Example:

    scala> case class Person(name: String)
    defined class Person
    
    scala> implicit val formats = DefaultFormats
    formats: net.liftweb.json.DefaultFormats.type = net.liftweb.json.DefaultFormats$@39afbb7c
    
    scala> JObject(JField("name", JString("joe")) :: Nil).extractOpt[Person]
    res1: Option[Person] = Some(Person(joe))
  18. def extractOrElse[A](default: ⇒ A)(implicit formats: Formats, mf: Manifest[A]): A

    Attempt to extract a concrete Scala instance of type A from this JValue and, on failing to do so, return the default value instead.

    Attempt to extract a concrete Scala instance of type A from this JValue and, on failing to do so, return the default value instead.

    Value can be:

    • a case class
    • a primitive (String, Boolean, Date, etc.)>
    • any type which has a configured custom deserializer
    • a supported collection type of any of the above (List, Seq, Map[String, _], Set)

    Example:

    > case class Person(name: String)
    > JNothing.extractOrElse(Person("joe"))
    res0: Person("joe")
  19. def filter(p: (JValue) ⇒ Boolean): List[JValue]

    Return a List of all values which matches the given predicate, recursively.

    Return a List of all values which matches the given predicate, recursively.

    Example:

    > JArray(JInt(1) :: JInt(2) :: Nil) filter {
      case JInt(x) => x > 1
      case _ => false
    }
    res0: List[net.liftweb.json.JsonAST.JValue] = List(JInt(2))

    This operates recursively, so nested objects work too:

    > ((("boom" -> ("slam" -> "hello")) ~ ("shap" -> 3)): JObject) filter {
      case JString("hello") => true
      case _ => false
    }
    res0: List[net.liftweb.json.JsonAST.JValue] = List(JString(hello))
  20. def filterField(p: (JField) ⇒ Boolean): List[JField]

    Return a List of all fields that match the given predicate.

    Return a List of all fields that match the given predicate. Does not recurse into child elements, so this will only check a JObject's field values.

    Example:

    > JObject(JField("age", JInt(10))) filterField {
      case JField("age", JInt(x)) if x > 18 =>
        true
    
      case _ =>
        false
    }
    res0: List[net.liftweb.json.JsonAST.JField] = List()
    > JObject(JField("age", JInt(10))) filterField {
      case JField("age", JInt(x)) if x < 18 =>
        true
    
      case _ =>
        false
    }
    res1: List[net.liftweb.json.JsonAST.JField] = List(JField(age,JInt(10)))
    returns

    A List of JFields that match the given predicate p, or Nil if this JValue is not a JObject.

  21. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. def find(p: (JValue) ⇒ Boolean): Option[JValue]

    Return the first element from a JValue which matches the given predicate.

    Return the first element from a JValue which matches the given predicate.

    Example:

    > JArray(JInt(1) :: JInt(2) :: Nil) find { _ == JInt(2) }
    res0: Option[net.liftweb.json.JsonAST.JValue] = Some(JInt(2))
  23. def findField(p: (JField) ⇒ Boolean): Option[JField]

    Return the first field from this JValue which matches the given predicate.

    Return the first field from this JValue which matches the given predicate.

    When invoked on a JObject it will first attempt to see if the JObject has the field defined on it. Not finding the field defined, this method will recurse into the fields of that object and search for the value there. When invoked on or encountering a JArray during recursion this method will run its search on each member of the JArray.

    Example:

    > JObject(JField("age", JInt(2))) findField {
      case JField(n, v) =>
        n == "age"
    }
    res0: Option[net.liftweb.json.JsonAST.JField] = Some(JField(age,JInt(2))
  24. def fold[A](z: A)(f: (A, JValue) ⇒ A): A

    Fold over JValues by applying a function to each element.

    Fold over JValues by applying a function to each element.

    z

    The initial value for the fold.

    f

    The function to apply, which takes an accumulator and the next item as paramaters.

  25. def foldField[A](z: A)(f: (A, JField) ⇒ A): A

    Fold over a series of JFields applying a function to each one.

    Fold over a series of JFields applying a function to each one.

    z

    The initial value for the fold.

    f

    The function to apply, which takes an accumulator as its first parameter and the next field as its second.

  26. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  27. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  28. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  29. def map(f: (JValue) ⇒ JValue): JValue

    Return a new JValue resulting from applying the given function to each value, recursively.

    Return a new JValue resulting from applying the given function to each value, recursively.

    If this function is invoked on a JObject, it will iterate over the field values of that JObject. If this function is invoked on a JArray, it will iterate over the values of that JArray. If this function is invoked on any other kind of JValue it will simply pass that instance into the function you have provided.

    Example:

    JArray(JInt(1) :: JInt(2) :: Nil) map {
      case JInt(x) => JInt(x+1)
      case x => x
    }
  30. def mapField(f: (JField) ⇒ JField): JValue

    Return a new JValue resulting from applying the given function to each JField in a JObject or a JArray of JObject, recursively.

    Return a new JValue resulting from applying the given function to each JField in a JObject or a JArray of JObject, recursively.

    Example:

    JObject(("age", JInt(10)) :: Nil) map {
      case ("age", JInt(x)) => ("age", JInt(x+1))
      case x => x
    }
    See also

    transformField

  31. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. final def notify(): Unit
    Definition Classes
    AnyRef
  33. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  34. def remove(p: (JValue) ⇒ Boolean): JValue

    Return a JSON where all values matching the given predicate are removed.

    Return a JSON where all values matching the given predicate are removed.

    Example:

    > JArray(JInt(1) :: JInt(2) :: JNull :: Nil).remove(_ == JNull)
    res0: net.liftweb.json.JsonAST.JValue = JArray(List(JInt(1), JInt(2), JNothing))
  35. def removeField(p: (JField) ⇒ Boolean): JValue

    Return a JValue where all fields matching the given predicate are removed.

    Return a JValue where all fields matching the given predicate are removed.

    Example:

    > JObject(JField("age", JInt(10))) removeField {
      case JField("age", _) => true
      case _          => false
    }
  36. def replace(l: List[String], replacement: JValue): JValue

    Return a new JValue resulting from replacing the value at the specified field path with the replacement value provided.

    Return a new JValue resulting from replacing the value at the specified field path with the replacement value provided. This has no effect if the path is empty or if the value is not a JObject instance.

    Example:

    > JObject(List(JField("foo", JObject(List(JField("bar", JInt(1))))))).replace("foo" :: "bar" :: Nil, JString("baz"))
    JObject(List(JField("foo", JObject(List(JField("bar", JString("baz")))))))
  37. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  38. def toOpt: Option[JValue]
  39. def toString(): String
    Definition Classes
    AnyRef → Any
  40. def transform(f: PartialFunction[JValue, JValue]): JValue

    Return a new JValue resulting from applying the given partial function to each value within this JValue.

    Return a new JValue resulting from applying the given partial function to each value within this JValue.

    If this is a JArray, this means we will transform each value in the array and return an updated array.

    If this is a JObject, this means we will transform the value of each field of the object and the object in turn and return an updated object.

    If this is another type of JValue, the value is transformed directly.

    Note that this happens recursively, so you will receive both each value in an array and the array itself, or each field value in an object and the object itself. If an array contains arrays, we will recurse into them in turn.

    Examples:

    > JArray(JInt(1) :: JInt(2) :: Nil) transform {
      case JInt(x) =>
        JInt(x+1)
    }
    res0: net.liftweb.json.JsonAST.JValue = JArray(List(JInt(2), JInt(3)))

    Without type matching, notice that we get the result of the transform replacing the array:

    > JArray(JInt(1) :: JInt(2) :: Nil) transform {
      case _ =>
        JString("hello")
    }
    res0: net.liftweb.json.JsonAST.JValue = JString("hello")
    returns

    This JValue with its child values recursively transformed by the given PartialFunction, when defined. If the PartialFunction is undefined, leaves the child values untouched.

  41. def transformField(f: PartialFunction[JField, JField]): JValue

    Return a new JValue resulting from applying the given partial function f to each field in JSON.

    Return a new JValue resulting from applying the given partial function f to each field in JSON.

    Example:

    JObject(("age", JInt(10)) :: Nil) transformField {
      case ("age", JInt(x)) => ("age", JInt(x+1))
    }
  42. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  45. def withFilter(p: (JValue) ⇒ Boolean): WithFilter

    Create a new instance of WithFilter for Scala to use when using this JValue in a for comprehension.

Inherited from Diffable

Inherited from AnyRef

Inherited from Any

Ungrouped