Questions tagged [json4s]

A single AST to be used by other scala json libraries

At this moment there are at least 6 json libraries for scala, not counting the java json libraries. All these libraries have a very similar AST. This project aims to provide a single AST to be used by other scala json libraries.

At this moment the approach taken to working with the AST has been taken from lift-json and the native package is in fact lift-json but outside of the lift project.

https://github.com/json4s/json4s

449 questions
0
votes
1 answer

Splicing json text into json4s ast without parsing

I have a string, which contains valid json. I'd like to add that json as a JField in a larger json4s AST I'm building, but it'd be nice to avoid having to parse the json into an AST first. I trust it. // this would work, but I'd prefer to avoid…
randomstatistic
  • 800
  • 5
  • 11
0
votes
1 answer

Replacing Fields in JSON with New Object using json4s

I have a scala app in which I'm using json4s to do some json manipulation. I have a few fields that I would like to convert into a new object. For example I have the…
Steve Y.
  • 87
  • 1
  • 6
0
votes
1 answer

Scala JSON4S to return a triple during field deserialization

I'm working with JSON4S and it handles missing fields correctly, when the corresponding object's field is an option. I'm using implicit val formats = Serialization.formats(NoTypeHints) + new org.json4s.ext.EnumNameSerializer(E) and…
Dyin
  • 5,815
  • 8
  • 44
  • 69
0
votes
1 answer

Can I use JSON4S hashCode method as a key?

Is it a right approach to use JSON4S hashCode JValue method as a key to store json in key-value store? I am embarrassed about it's length and possible collisions.
Andrey Filyanin
  • 87
  • 1
  • 11
0
votes
1 answer

scala json serialization missing fields (json4s)

I am using json4s to serialize some scala map objects. import org.apache.spark.util.StatCounter import org.json4s.DefaultFormats val m: scala.collection.Map[String, Map[String, StatCounter]] = Map("key" -> Map("secondKey" ->…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
0
votes
2 answers

how can i pattern match on runtime class in scala

I have a snippet of code like this: override def getOption[T: TypeTag: ClassTag](path: String): Option[T] = { implicitly[scala.reflect.ClassTag[T]].toString() match { case "java.lang.String" =>…
hiroprotagonist
  • 902
  • 1
  • 11
  • 24
0
votes
0 answers

Transforming the json data using scala to look like a normalized output

I have an input json which is read from a denormalized table. In my scala application, I need to normalize it before returning the resultset. If below is the sample input: inputJson = { "k1": "v0", "k2": [{ "k21": [ …
Gayatri Mahesh
  • 327
  • 1
  • 3
  • 12
0
votes
1 answer

How do I workaround a json4s bug so that an Option[Seq[_]] will deserialize into a None instead of Some(List())

I'm currently on json4s 3.2.10. I realize json4s is buggy and shouldn't be used for anything ever, but this is a legacy codebase and switching out the json parser is impractical currently. I have a situation where json fields that don't exist (and…
djsumdog
  • 2,560
  • 1
  • 29
  • 55
0
votes
1 answer

Remove json field (when empty value) in serialize with json4s

What is the best practice to remove json field (when empty value) with serialize using json4s? val json = ("foo" -> "bar") ~ ("fizz" -> "buzz") compact(render(json)) """ {"foo":"bar","fizz":"buzz"} """ val json = ("foo" -> "bar") ~ ("fizz" ->…
sh0hei
  • 51
  • 6
0
votes
1 answer

Getting type Mismatch error with List of Maps

I have method which should except a string and List of Map. I get an error on the second line as // get error as : type mismatch; found : List[scala.collection.immutable.Map[String,Any]] required: List[Map[String,org.json4s.JValue]] (which expands…
Bhaskar Mishra
  • 3,332
  • 7
  • 26
  • 36
0
votes
1 answer

How to serialize content of a Map with their toString?

I tried to to use json4s native library. Here is how I use it: Builder b = new JsonMessageBuilder(); Map> m2 = new HashMap<>(); m2.put("e", Arrays.asList(new…
user3663882
  • 6,957
  • 10
  • 51
  • 92
0
votes
1 answer

How do I deserialize a JSON file using json4s without reading into a string first?

I can read JSON from a file into a string and then deserialize like so: val jsonString = new String(Files.readAllBytes(Paths.get("myObject.json"))) val json = parse(jsonString) val myObject = json.extract[MyClass] This seems inefficient to me,…
arosca
  • 469
  • 7
  • 15
0
votes
1 answer

scala json4s create json with optional/nullable field throws exception

I am fairly new to scala and functional programming. I have this piece of code written by someone which constructs json using json4s library, val json = "body" -> ...toList.map { case (title, attrs) => ("name", tag) ~ ("attributes",…
raksja
  • 3,969
  • 5
  • 38
  • 44
0
votes
2 answers

Trouble Serializing Enums with JSON4S

I have an enum class hierarchy like this: abstract class EnumBase { def code: String } abstract class EnumObject[EnumT <: EnumBase] {...} I use this in many places. Here is one example: sealed abstract case class StateCode(code: String) extends…
Vidya
  • 29,932
  • 7
  • 42
  • 70
0
votes
1 answer

Spark - Task Scheduler Error while parsing JSON

I'm trying to read 5 terabytes of json into an RDD of custom objects using json4s. There are 50,000 files of around 100 MB each. For some reason, if I set my executor size to 16G, I get the following error. ERROR TaskSchedulerImpl: Lost executor foo…
Luke
  • 6,699
  • 13
  • 50
  • 88