Conversions between String and Date.
A difference between two JSONs (j1 diff j2).
A difference between two JSONs (j1 diff j2).
what has changed from j1 to j2
what has been added to j2
what has been deleted from j1
Serializer which serializes all fields of a class too.
Serializer which serializes all fields of a class too.
Serialization can be intercepted by giving two optional PartialFunctions as constructor parameters:
FieldSerializer[WildDog]( renameTo("name", "animalname") orElse ignore("owner"), renameFrom("animalname", "name") )
Formats to use when converting JSON.
Formats to use when converting JSON. Formats are usually configured by using an implicit parameter:
implicit val formats = net.liftweb.json.DefaultFormats
Use full class name as a type hint.
Use short class name as a type hint.
Type hints can be used to alter the default conversion rules when converting Scala instances into JSON and vice versa.
Type hints can be used to alter the default conversion rules when converting Scala instances into JSON and vice versa. Type hints must be used when converting class which is not supported by default (for instance when class is not a case class).
Example:
class DateTime(val time: Long) val hints = new ShortTypeHints(classOf[DateTime] :: Nil) { override def serialize: PartialFunction[Any, JObject] = { case t: DateTime => JObject(JField("t", JInt(t.time)) :: Nil) } override def deserialize: PartialFunction[(String, JObject), Any] = { case ("DateTime", JObject(JField("t", JInt(t)) :: Nil)) => new DateTime(t.longValue) } } implicit val formats = DefaultFormats.withHints(hints)
(Since version 3.0) Please switch using JsonAST's render methods instead of relying on Printer.
Default date format is UTC time.
Computes a diff between two JSONs.
Function to extract values from JSON AST using case classes.
Function to extract values from JSON AST using case classes.
See: ExtractionExamples.scala
Basic implicit conversions from primitive types into JSON.
Basic implicit conversions from primitive types into JSON. Example:
import net.liftweb.json.Implicits._ JObject(JField("name", "joe") :: Nil) == JObject(JField("name", JString("joe")) :: Nil)
This object contains the abstract syntax tree (or AST) for working with JSON objects in lift-json.
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 }
A DSL to produce valid JSON.
A DSL to produce valid JSON. Example:
import net.liftweb.json.JsonDSL._ ("name", "joe") ~ ("age", 15) == JObject(JField("name",JString("joe")) :: JField("age",JInt(15)) :: Nil)
JSON parser.
Function to merge two JSONs.
Do not use any type hints.
Functions to serialize and deserialize a case class.
Functions to serialize and deserialize a case class. Custom serializer can be inserted if a class is not a case class.
Example:
val hints = new ShortTypeHints( ... ) implicit val formats = Serialization.formats(hints)
net.liftweb.json.TypeHints
Functions to convert between JSON and XML.
Printer converts JSON to String.
Printer converts JSON to String.
Before printing a JValue
needs to be rendered into scala.text.Document.
Example:
pretty(render(json))
(Since version 3.0) Please switch using JsonAST's render methods instead of relying on Printer.
(Since version 3.0) Please switch to using compactRender instead.
(Since version 3.0) Please switch to using prettyRender instead.
(Since version 3.0) Please switch to using prettyRender or compactRender instead.