case class JObject(obj: List[JField]) extends JValue with Product with Serializable
- Alphabetic
- By Inheritance
- JObject
- Serializable
- Serializable
- Product
- Equals
- JValue
- Diffable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
++(other: JValue): JValue
Concatenate this
JValuewith anotherJValue.Concatenate this
JValuewith anotherJValue.Example:
> JArray(JInt(1) :: JInt(2) :: Nil) ++ JArray(JInt(3) :: Nil) res0: JArray(List(JInt(1), JInt(2), JInt(3)))
- Definition Classes
- JValue
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
\[A <: JValue](clazz: Class[A]): List[JValue.\.A.Values]
Find immediate children of this
JValuethat match a specificJValuesubclass.Find immediate children of this
JValuethat match a specificJValuesubclass.This methid will search a
JObjectorJArrayfor values of a specific type and return aListof 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.- Definition Classes
- JValue
-
def
\(nameToFind: String): JValue
An XPath-like expression to find a child of a
JObjector aJArrayofJObjectby name.An XPath-like expression to find a child of a
JObjector aJArrayofJObjectby name. If you call this method on anything other than aJObjectorJArrayofJObjects you'll get aJNothing.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 theJValueyou're operating on is actually an array of objects, you'll get back aJArrayof the result of executing\on each object in the array. In the event nothing is found, you'll get aJNothing.- Definition Classes
- JValue
-
def
\\[A <: JValue](clazz: Class[A]): List[JValue.\\.A.Values]
Find all descendants of this
JValuethat match a specificJValuesubclass.Find all descendants of this
JValuethat match a specificJValuesubclass.Unlike its cousin
\, this method will recurse down into all children looking for type matches searching aJObjectorJArrayfor values of a specific type and return aListof 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)
- Definition Classes
- JValue
-
def
\\(nameToFind: String): JObject
Find all children of a
JObjectwith the matching name, returning an emptyJObjectif no matches are found.Find all children of a
JObjectwith the matching name, returning an emptyJObjectif 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))))
- Definition Classes
- JValue
-
def
apply(i: Int): JValue
Return the element in the
i-th position from aJArray.Return the element in the
i-th position from aJArray. Will returnJNothingwhen invoked on any other kind ofJValue.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)
- Definition Classes
- JValue
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
children: List[JValue]
Return direct child elements of this
JValue, if thisJValueis aJObjectorJArray.Return direct child elements of this
JValue, if thisJValueis aJObjectorJArray.This method is useful for getting all the values of a
JObjectorJArrayand will return them as aList[JValue]. If theJValueyou invoke this method on is not aJObjectorJArrayyou will instead getNil.Example:
> JArray(JInt(1) :: JInt(2) :: Nil).children List(JInt(1), JInt(2))
- Definition Classes
- JValue
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
diff(other: json.JValue): Diff
Return a diff.
Return a diff.
- Definition Classes
- Diffable
- See also
net.liftweb.json.Diff#diff
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(that: Any): Boolean
- Definition Classes
- JObject → Equals → AnyRef → Any
-
def
extract[A](implicit formats: Formats, mf: Manifest[A]): A
Extract a value into a concrete Scala instance from its
JValuerepresentation.Extract a value into a concrete Scala instance from its
JValuerepresentation.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")
- Definition Classes
- JValue
-
def
extractOpt[A](implicit formats: Formats, mf: Manifest[A]): Option[A]
Optionally extract a value into a concrete Scala instance from its
JValuerepresentation.Optionally extract a value into a concrete Scala instance from its
JValuerepresentation.This method will attempt to extract a concrete Scala instance of type
A, but if it fails it will return ascala.Noneinstead of throwing an exception asextractwould.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))
- Definition Classes
- JValue
-
def
extractOrElse[A](default: ⇒ A)(implicit formats: Formats, mf: Manifest[A]): A
Attempt to extract a concrete Scala instance of type
Afrom thisJValueand, on failing to do so, return the default value instead.Attempt to extract a concrete Scala instance of type
Afrom thisJValueand, 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")
- Definition Classes
- JValue
-
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))
- Definition Classes
- JValue
-
def
filterField(p: (JField) ⇒ Boolean): List[JField]
Return a
Listof all fields that match the given predicate.Return a
Listof all fields that match the given predicate. Does not recurse into child elements, so this will only check aJObject'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
ListofJFields that match the given predicatep, orNilif thisJValueis not aJObject.
- Definition Classes
- JValue
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
find(p: (JValue) ⇒ Boolean): Option[JValue]
Return the first element from a
JValuewhich matches the given predicate.Return the first element from a
JValuewhich matches the given predicate.Example:
> JArray(JInt(1) :: JInt(2) :: Nil) find { _ == JInt(2) } res0: Option[net.liftweb.json.JsonAST.JValue] = Some(JInt(2))
- Definition Classes
- JValue
-
def
findField(p: (JField) ⇒ Boolean): Option[JField]
Return the first field from this
JValuewhich matches the given predicate.Return the first field from this
JValuewhich matches the given predicate.When invoked on a
JObjectit will first attempt to see if theJObjecthas 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 aJArrayduring recursion this method will run its search on each member of theJArray.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))
- Definition Classes
- JValue
-
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.
- Definition Classes
- JValue
-
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.
- Definition Classes
- JValue
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- JObject → AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map(f: (JValue) ⇒ JValue): JValue
Return a new
JValueresulting from applying the given function to each value, recursively.Return a new
JValueresulting 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 thatJObject. If this function is invoked on aJArray, it will iterate over the values of thatJArray. If this function is invoked on any other kind ofJValueit 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 }
- Definition Classes
- JValue
-
def
mapField(f: (JField) ⇒ JField): JValue
Return a new
JValueresulting from applying the given function to eachJFieldin aJObjector aJArrayofJObject, recursively. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val obj: List[JField]
-
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))
- Definition Classes
- JValue
-
def
removeField(p: (JField) ⇒ Boolean): JValue
Return a
JValuewhere all fields matching the given predicate are removed.Return a
JValuewhere all fields matching the given predicate are removed.Example:
> JObject(JField("age", JInt(10))) removeField { case JField("age", _) => true case _ => false }
- Definition Classes
- JValue
-
def
replace(l: List[String], replacement: JValue): JValue
Return a new
JValueresulting from replacing the value at the specified field path with the replacement value provided.Return a new
JValueresulting 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 aJObjectinstance.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")))))))
- Definition Classes
- JValue
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toOpt: Option[JValue]
- Definition Classes
- JValue
-
def
transform(f: PartialFunction[JValue, JValue]): JValue
Return a new
JValueresulting from applying the given partial function to each value within thisJValue.Return a new
JValueresulting from applying the given partial function to each value within thisJValue.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
JValuewith its child values recursively transformed by the givenPartialFunction, when defined. If thePartialFunctionis undefined, leaves the child values untouched.
- Definition Classes
- JValue
-
def
transformField(f: PartialFunction[JField, JField]): JValue
Return a new
JValueresulting from applying the given partial functionfto each field in JSON.Return a new
JValueresulting from applying the given partial functionfto each field in JSON.Example:
JObject(("age", JInt(10)) :: Nil) transformField { case ("age", JInt(x)) => ("age", JInt(x+1)) }
- Definition Classes
- JValue
-
def
values: Map[String, Any]
Return a representation of the values in this
JValuein a native Scala structure. -
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withFilter(p: (JValue) ⇒ Boolean): WithFilter
Create a new instance of
WithFilterfor Scala to use when using thisJValuein a for comprehension.Create a new instance of
WithFilterfor Scala to use when using thisJValuein a for comprehension.- Definition Classes
- JValue