object JsonAST
This object contains the abstract syntax tree (or AST) for working with JSON objects in lift-json.
The purpose of the JSON AST is to represent and manipulate JSON by leveraging Scala language features like types, case classes, etc. The AST should allow you to represent anything you could imagine from JSON land using the Scala type system.
Everything in the AST has a single root: JValue. A JValue could, quite literally, be anything.
It could be an an object (represented by JObject
), a string (JString
), a null
(JNull
), and so on. So, when constructing a JSON object with the AST directly you might
construct something like the following:
JObject(JField("bacon", JBool(true)) :: JField("spinach", JBool(false)))
Once serialized to the string representation of JSON you would end up with the following:
{ "bacon":true, "spinach":false }
- Alphabetic
- By Inheritance
- JsonAST
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
sealed
trait
DoubleRenderer
extends (Double) ⇒ String
Parent trait for double renderers, which decide how doubles contained in a JDouble are rendered to JSON string.
- case class JArray (arr: List[JValue]) extends JValue with Product with Serializable
- case class JBool (value: Boolean) extends JValue with Product with Serializable
- case class JDouble (num: Double) extends JValue with Product with Serializable
- case class JField (name: String, value: JValue) extends Product with Serializable
- case class JInt (num: BigInt) extends JValue with Product with Serializable
- case class JObject (obj: List[JField]) extends JValue with Product with Serializable
- case class JString (s: String) extends JValue with Product with Serializable
-
sealed abstract
class
JValue
extends Diffable
The base type for all things that represent distinct JSON entities in the AST.
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. - case class RenderIntermediaryDocument (value: JValue) extends Product with Serializable
-
case class
RenderSettings
(indent: Int, escapeChars: Set[Char] = Set(), spaceAfterFieldName: Boolean = false, doubleRenderer: DoubleRenderer = RenderSpecialDoubleValuesAsNull) extends Product with Serializable
RenderSettings allows for customizing how JSON is rendered to a String.
RenderSettings allows for customizing how JSON is rendered to a String. At the moment, you can customize the indentation (if 0, all the JSON is printed on one line), the characters that should be escaped (in addition to a base set that will always be escaped for valid JSON), and whether or not a space should be included after a field name.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
compactRender(value: JValue, appendable: Appendable): String
Render
value
to the givenappendable
usingRenderSettings.compact
. -
def
compactRender(value: JValue): String
Renders JSON directly to string in compact format.
Renders JSON directly to string in compact format. This is an optimized version of compact(render(value)) when the intermediate Document is not needed.
-
def
concat(values: JValue*): JValue
Concatenate a sequence of
JValue
s together.Concatenate a sequence of
JValue
s together.This would be useful in the event that you have a handful of
JValue
instances that need to be smacked together into one unit.For example:
concat(JInt(1), JInt(2)) == JArray(List(JInt(1), JInt(2)))
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
prettyRender(value: JValue, appendable: Appendable): String
Render
value
to the givenappendable
usingRenderSettings.pretty
. -
def
prettyRender(value: JValue): String
Render
value
usingRenderSettings.pretty
. - def render(value: JValue): RenderIntermediaryDocument
-
def
render(value: JValue, settings: RenderSettings, appendable: Appendable = new StringBuilder()): String
Render
value
to the givenappendable
(aStringBuilder
, by default) using the givensettings
.Render
value
to the givenappendable
(aStringBuilder
, by default) using the givensettings
. The appendable'stoString
will be called and the result will be returned. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
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
- @throws( ... )
-
object
FailToRenderSpecialDoubleValues
extends DoubleRenderer with Product with Serializable
A
DoubleRenderer
that throws anIllegalArgumentException
when the special valuesNaN
,-Infinity
, andInfinity
are encountered.A
DoubleRenderer
that throws anIllegalArgumentException
when the special valuesNaN
,-Infinity
, andInfinity
are encountered. Other doubles are rendered normally usingtoString
. - object JNothing extends JValue with Product with Serializable
- object JNull extends JValue with Product with Serializable
- object JObject extends Product with Serializable
- object JValue extends Mergeable
- object RenderSettings extends Serializable
-
object
RenderSpecialDoubleValuesAsIs
extends DoubleRenderer with Product with Serializable
A
DoubleRenderer
that renders special valuesNaN
,-Infinity
, andInfinity
as-is usingtoString
.A
DoubleRenderer
that renders special valuesNaN
,-Infinity
, andInfinity
as-is usingtoString
. This is not valid JSON, meaning JSON libraries generally won't be able to parse it (including lift-json!), but JavaScript can eval it. Other double values are also rendered the same way.Usage is not recommended.
-
object
RenderSpecialDoubleValuesAsNull
extends DoubleRenderer with Product with Serializable
A
DoubleRenderer
that renders special valuesNaN
,-Infinity
, andInfinity
asnull
.A
DoubleRenderer
that renders special valuesNaN
,-Infinity
, andInfinity
asnull
. Other doubles are rendered normally usingtoString
.