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
5
votes
4 answers

Extract Options from potentially null JSON values using for expression

I have a JSON document where some values can be null. Using for expressions in json4s, how I can yield None, instead of nothing? The following will fail to yield when the value for either of the fields FormattedID or PlanEstimate is null. val j:…
Synesso
  • 37,610
  • 35
  • 136
  • 207
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
4
votes
1 answer

Deserializing Option returns None instead of an exception in json4s

When running the following code I would expect an exception, but I get None instead. Is that expected? import org.json4s.jackson.JsonMethods import org.json4s.{DefaultFormats, Formats} implicit val f: Formats = DefaultFormats val json ="{ \"a\" : {…
igreenfield
  • 1,618
  • 19
  • 36
4
votes
2 answers

Structural equality affected by location of case class definition after deserialisation

Why is structural equality comparison affected, after deserialisation to case class instance, by the location of case class definition being inside or outside another class. For example, the assertion in the following snippet package…
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
4
votes
2 answers

EMR 5.21 , Spark 2.4 - Json4s Dependency broken

Issue In EMR 5.21 , Spark - Hbase integration is broken. df.write.options().format().save() fails. Reason is json4s-jackson version 3.5.3 in spark 2.4 , EMR 5.21 it works fine in EMR 5.11.2 , Spark 2.2 , son4s-jackson version 3.2.11 Problem is…
4
votes
2 answers

Spark + Json4s serialization problems

I am using Json4s classes inside of a Spark 2.2.0 closure. The "workaround" for a failure to serialize DefaultFormats is to include their definition inside every closure executed by Spark that needs them. I believe I have done more than I needed to…
pferrel
  • 5,673
  • 5
  • 30
  • 41
4
votes
2 answers

Extract nested JSON element using scala

I have the following code in Scala. My goal is to extract the value(s) of a key without knowing how many and how deep they are. import org.json4s.jackson.JsonMethods._ import org.json4s.{DefaultFormats, JField, JObject, JString, JValue} …
geo
  • 516
  • 5
  • 12
4
votes
2 answers

Json4s: Classes defined in method bodies are not supported

I have a Seq of these: case class IntPane( override val duration: FiniteDuration, override val values: mutable.Map[String, Int], override val default: Int) extends BasePane[Int](duration,…
4
votes
1 answer

How to read a json response from a akka-http response entity using json4s

I am trying to invoke the google geocoding api and retrieve the response. lazy val geoCodingConnectionFlow: Flow[HttpRequest, HttpResponse, Any] = Http().outgoingConnectionHttps(config.getString("services.geoCodingApiHost"),…
Phani
  • 1,851
  • 2
  • 15
  • 28
4
votes
2 answers

scala json4s, can't convert LocalDate

I'm having an issue with org.json4s (scala), joda.time.LocalDate and org.json4s.ext.JodaTimeSerializers. Given that JodaTimeSerializers.all has a LocalDate conversion in it, i was hoping that i could do the following, but I get the exception shown…
ekydfejj
  • 339
  • 2
  • 14
4
votes
0 answers

Arbitrary nested JSON to Map in Scala using json4s

I am using json4s in Scala. Now, given the following JSON: { 'k1': [ {"a" : "hello1", "b": "city1" }, {"a" : "hello2", "b": "city2" }, {"a" : "hello2", "b": "city2" } ], 'k2': [ {"a" : "hello1", "b": "city1" }, {"a" : "hello2", "b":…
tuxdna
  • 8,257
  • 4
  • 43
  • 61
4
votes
2 answers

Which JSON library to use when storing case objects?

I need to serialize akka events to json. Based on "What JSON library to use in Scala?" I tried several libraries. Since my serializer should know nothing of all my concrete events, the events consisting of case classes and case objects should be…
Beat Sager
  • 41
  • 2
4
votes
1 answer

Serializing sequences of AnyVal with json4s

I have a problem when trying to serialize sequences of AnyVal using json4s in scala. Here is a test using FunSuite that reproduces the problem: import org.json4s._ import org.json4s.jackson.JsonMethods._ import…
Alexandre
  • 316
  • 2
  • 7
4
votes
2 answers

Error calling `JValue.extract` from distributed operations in spark-shell

I am trying to use the case class extraction feature of json4s in Spark, ie calling jvalue.extract[MyCaseClass]. It works fine if I bring the JValue objects into the master and do the extraction there, but the same calls fail in the workers: import…
Daniel Mahler
  • 7,653
  • 5
  • 51
  • 90
4
votes
1 answer

How to read data from file in task and use it to set another setting?

We are migrating our application to Play Framework. We've been working with the gradle build system and are facing a couple of issues with sbt. We use jooq for our database, which means that our build file needs to contain the database…
Rohan Prabhu
  • 7,180
  • 5
  • 37
  • 71