Questions tagged [lift-json]

the lift-json parsing and formatting utilities for JSON

A JSON abstract syntax tree (AST) providing the following features:

  • Fast JSON parser
  • LINQ style queries
  • Case classes can be used to extract values from parsed JSON
  • Diff & merge
  • DSL to produce valid JSON
  • XPath like expressions and HOFs to manipulate JSON
  • Pretty and compact printing
  • XML conversions
  • Serialization
  • Low level pull parser API

Github: https://github.com/lift/lift/tree/master/framework/lift-base/lift-json/

130 questions
37
votes
5 answers

Scala 2.10 + Json serialization and deserialization

Scala 2.10 seems to have broken some of the old libraries (at least for the time being) like Jerkson and lift-json. The target usability is as follows: case class Person(name: String, height: String, attributes: Map[String, String], friends:…
user1698607
  • 381
  • 1
  • 3
  • 7
21
votes
4 answers

How to convert a JSON JString value to an ordinary String in Lift?

Having a jString : JString value holding an "abc" string inside I get "JString(abc)" : String if I call jString.toString. How do I get "abc" : String instead?
Ivan
  • 63,011
  • 101
  • 250
  • 382
12
votes
1 answer

Lift-json extract json with 'type' field into a case class

I am trying to extract JSON into a case class using lift-json. Here is my case class: case class Person(name: String, age: Int) Here is the json { "name": "Some Name", "age": 24, type: "Student" } How can I extract the type field into an instance…
Chas Lemley
  • 346
  • 1
  • 9
9
votes
3 answers

lift-json with scala 2.10

I am following the tutorial here and stuck with json-lift dependency. This is the dependency in my plugings.sbt file: addSbtPlugin("net.liftweb" %% "lift-json" % "2.4") The error is below and it seems to be something related to scala 10.2 not being…
haknick
  • 1,892
  • 1
  • 20
  • 28
9
votes
3 answers

How to Manipulate JSON AST in Scala

I am experimenting with the json4s library (based on lift-json). One of the things I would like to do is to parse a JSON string into an AST, and then manipulate it. For example, I would like to upsert a field (insert the field into the AST if it…
Eduardo
  • 8,362
  • 6
  • 38
  • 72
7
votes
1 answer

Polymorphic lift-json deserialization in a composed class

I am trying to automatically deserialize json object to a scala class using Lift-Json with a coordinate class inside used to store GeoJson information. case class Request(name:String, geometry:Geometry) sealed abstract class Geometry case class…
Matroska
  • 6,885
  • 14
  • 63
  • 99
7
votes
2 answers

lift-json manipulation - adding in the right place

consider the following json: { "type":"A1", "system":{ "path":"/example.org/FooBar", "lastModified":"2013-10-01T12:00:00Z" }, "fields":{ "foo1":["bar1"], "foo2":["bar2"], "foo3":["bar3"] } } now, using lift-json, i…
gilad hoch
  • 2,846
  • 2
  • 33
  • 57
7
votes
4 answers

How to fill case class from json with partial data?

import net.liftweb.json._ import net.liftweb.json.JsonParser._ object test02 extends App { implicit val formats = DefaultFormats case class User( id: Int = 0, name: String = "John Doe", gender: String = "M") val…
codez
  • 1,381
  • 1
  • 18
  • 28
6
votes
2 answers

Serialize a map that doesn't have a string as a key with lift-json

It seems like lift-json is limited to maps that have Strings as keys. What is the best way to bypass this limitation ?
Atol
  • 569
  • 4
  • 12
5
votes
2 answers

Convert lift-json JValue into MongoDBObject using Casbah?

I'm trying to convert a parsed JSON document in a lift-json's JValue into a Casbah MongoDBObject - is there a way to do this?
outside2344
  • 2,075
  • 2
  • 29
  • 52
5
votes
2 answers

Salat not deserializing collections that map to Option[Set[A]]

I asked this question in scala-salat Google group, but no response there for a few days, hence trying here. I have a case class which has a collection wrapped in an Option. case class SomeClass( var name:Option[String]=None, var…
lobster1234
  • 7,679
  • 26
  • 30
5
votes
2 answers

Check if an object has a field in json4s/lift-json

I have a json with some fields and I want to check if some of them are present. I'm extracting the value and testing it against JNothing, but it is too verbose: val json: JValue = ... val jsonIsType1 = (json \ "field1") != JNothing && (json \…
douglaz
  • 1,306
  • 2
  • 13
  • 17
5
votes
1 answer

Parse Json List with 1 element (Scala/liftweb)

I'm running into a situation where I'm retrieving some Json from an external server (I do not have any control over that server). The Json has one element that may occur 1 or more times. I'm trying to parse it using the net.liftweb.json facilities…
Gero
  • 2,967
  • 6
  • 22
  • 20
4
votes
5 answers

validating json in scala with lift-json

I'd like to validate json contains a list of key/values before attempting to marshall into a case class using lift-json. The data might be nested. For example: { "name": "stack", "desc": "desc", "age": 29, "address": { "street": "123 elm", …
Todd M
  • 1,012
  • 1
  • 15
  • 25
4
votes
3 answers

Why do I get "$outer" In my json string when using lift-json?

Let me preface by saying I am new to working with json and serialization and such. I am trying to create some json from some case classes. Here is my code from a scala worksheet I'm playing with: import net.liftweb.json.DefaultFormats import…
A.A.
  • 402
  • 1
  • 4
  • 19
1
2 3
8 9