Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jan 30 2019 12:25
    justdoit0823 starred json4s/json4s
  • Jan 30 2019 11:05
    ericxsun commented #212
  • Jan 26 2019 13:29

    seratch on v3.6.4


  • Jan 26 2019 13:28

    seratch on 3.6

    version 3.6.4 Start 3.6.5 dev (compare)

  • Jan 26 2019 12:53

    seratch on 3.6

    Reduced OrElse objects allocati… Merge branch '3.6' into pr-580-… Merge branch '3.6' into pr-580-… and 1 more (compare)

  • Jan 26 2019 12:53
    seratch closed #582
  • Jan 26 2019 12:39
    seratch synchronize #582
  • Jan 26 2019 12:39

    seratch on 3.6

    fix Type alias for parameterize… Merge branch '3.6' into pr-577-… Merge pull request #581 from se… (compare)

  • Jan 26 2019 12:39
    seratch closed #581
  • Jan 26 2019 12:38
    seratch synchronize #582
  • Jan 26 2019 12:38
    seratch opened #582
  • Jan 26 2019 12:30
    seratch synchronize #581
  • Jan 26 2019 12:30

    seratch on 3.6

    Add 3.6.3 to previous versions … (compare)

  • Jan 26 2019 12:25

    seratch on master

    Reduced OrElse objects allocati… (compare)

  • Jan 26 2019 12:25
    seratch closed #580
  • Jan 26 2019 12:25
    seratch closed #579
  • Jan 26 2019 12:25
    seratch commented #580
  • Jan 26 2019 11:03
    poslegm commented #580
  • Jan 26 2019 10:56
    poslegm synchronize #580
  • Jan 26 2019 10:32
    seratch commented #580
marios iliofotou
Hey guys, I create a SO question for what I asked few days, back, let me know if you can help, thanks! http://stackoverflow.com/questions/41709882/json4s-extractor-for-partial-fields-when-we-care-to-preserve-the-original-json
marios iliofotou
@mxl thanks for the answer on SO!
marios iliofotou
Hi all! is there a way for json4s to give the line causing the syntax error in the stack trace?
Justin Reeves
I'm a novice having some trouble using Json4s to extract a given hit from this json response. First thing first I have to decide on is the right data structure.
Reduced that down so there's only one result showing.
Justin Reeves
I got it. Wound up going through it with val hits = (json \ "hits" \ "hits").extract[List[Map[String,JValue]]] then dealing with the hit seperately.
Luis Medina

There is a weird issue (or is it expected?) where a numeric value in a JSON keeps getting extracted as a String even though an error should probably get thrown.
As an example, say I have a json string that looks like this:

    "test": 3

When I go to extract the "test" field from this JSON as a String, I'm expecting it to fail:

def getVal[T: Manifest](json: JValue, fieldName: String): Option[T] = {
    val field = json findField {
      case JField(name, _) if name == fieldName => true
      case _ => false

    field.map {
      case (_, value) => value.extract[T]

val json = JsonMethods.parse("""{"test":3}""")
val s: Option[String] = getVal[String](json, "test")  // Some(3)

Is there any way to force a type mismatch to cause this to fail?

Jason Fine


I am wondering about a serialization situation I've encountered. When I have a class which extends another class with the same fields, they get serialized twice. For example:

  abstract class Base(a: Int, b: String) {
    def doSomething(): String = a.toString + b
  case class MyClass(a: Int, b: String) extends Base(a, b)

when serializing an instance of MyClass we end up with the following:

Note: This won't happen if the fields are not used in the base class. I believe this is an issue with how getDecleredFields works, perhaps you want to filter out non-public fields from the super class?

Mark Grey
Hi friends. I am wondering if there is an easy way to obtain a JValue from a case class if I have a Formats and the necessary typeclasses in scope?
right now im using parse(write(cc)) but that seems a bit silly since it stringifies it and then reparses it
marios iliofotou
@DeaconDesperado u r looking for render()
Shivam Sharma
does json4s support Either datatype parsing in scala
Sumana Ravikrishnan
Hey guys. I'm getting a error: not found: value JNothing error even after importing import org.json4s._. I'm running it in spark-shell using Scala.
I'm not sure why this error is popping up. Does anyone have an idea?
Justin Reeves
Yo. Trying to deal with the fact that my data is standardized but I do need a Boolean extracted from the common cases. I tried writing a custom serializer in a scala worksheet but it says it can't find the constructor:
import org.json4s._
import org.json4s.native.JsonMethods._
import org.json4s.DefaultFormats
import org.json4s.native.JsonMethods.parse

class LooseBoolean(v: Option[Boolean]) {
  val value = v

class LooseBooleanSerializer(trueStrings: Seq[String], falseStrings: Seq[String])
  extends CustomSerializer[LooseBoolean](format => (
    case JBool(x) => new LooseBoolean(Some(x))
    case JString(x) if x != null  => new LooseBoolean(Some(trueStrings.contains(x) || !falseStrings.contains(x)))
    case _ => new LooseBoolean(None)
    case x: LooseBoolean => JBool(x.value.get)

val t = Seq("t","T","1","Yes")
val f = Seq("f","F","0","No")

implicit val jsonFormats: Formats = DefaultFormats + new LooseBooleanSerializer(t,f)

val json =
          |"myInt" : 123,
          |"myDouble" : 123.456,
          |"myWord" : "werd",
          |"myBoolean" : true,
          |"myIntStr": "123",
          |"myDoubleStr": "123.456",
          |"myBooleanTrueStr": "true",
          |"myBooleanFalseStr": "false",
          |"myBoolean_t": "t",
          |"myBoolean_f": "f",
          |"myBoolean_T": "T",
          |"myBoolean_Yes": "Yes",
          |"myBoolean_F": "F",
          |"myBoolean_1": "1",
          |"myBoolean_0": "0",
          |"myNull" : null
(json \ "myBoolean").extract[LooseBoolean]
@nonconvergent that actually works for me; can you try it outside a worksheet? I’ve never had much luck debugging json4s issues in an intellij worksheet
Justin Reeves
Justin Reeves
@breadmenace_twitter trying putting it inside my scala-test and then just running that just that test and get the same result.
Is there any support for java.timeserialization?
Alexey Novakov
I've used this PR for java.time: json4s/json4s#243
Hanns Holger Rutz
Hi. Quick question - why would I choose native over jackson or the other way around? I want to parse JSON coming in from http via dispatch.
Hanns Holger Rutz

Another question. Parsing dates...

No usable value for created
Invalid date '2017-01-29T14:54:43.792240')

My case class has java.util.Date. How can I fix this?

Alexey Novakov
@Sciss I am not sure, but looks like date value can't be parsed because you are using non-default date format or the overriden format does match to the sample value above.
default is "yyyy-MM-dd'T'HH:mm:ss'Z'"
can't go deeper at the moment, sorry
Justin Potter
Anyone know if it's possible to nest CustomSerializers?
Justin Potter
For example, if I want to create a CustomSerializer for the following:
case class User(
  id: String,
  name: String,
  phoneNumbers: Seq[Phone])
Where both User and Phone have their own custom serializer
But I somehow need to nest the Phone deserializer with the User deserializer
Justin Potter
Balázs Kossovics
Balázs Kossovics
I'd need this in the other direction, i.e. decoding escaped non-ascii characters from a json string
Balázs Kossovics
scala> parse(""""M\xe9ditel"""")
com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'x' (code 120)
 at [Source: "M\xe9dit"; line: 1, column: 5]
  at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1581)
  at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:533)
  at com.fasterxml.jackson.core.base.ParserMinimalBase._handleUnrecognizedCharacterEscape(ParserMinimalBase.java:510)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._decodeEscaped(ReaderBasedJsonParser.java:2208)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString2(ReaderBasedJsonParser.java:1773)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._finishString(ReaderBasedJsonParser.java:1747)
  at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getText(ReaderBasedJsonParser.java:233)
  at org.json4s.jackson.JValueDeserializer.deserialize(JValueDeserializer.scala:24)
  at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1511)
  at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1136)
  at org.json4s.jackson.JsonMethods$class.parse(JsonMethods.scala:25)
  at org.json4s.jackson.JsonMethods$.parse(JsonMethods.scala:55)
  ... 42 elided
is this possible?
Hey folks, this is probably a very noob question: how can one deserialize a (tagged) union type from JSON? I'm trying to use a sealed class + case class hierarchy and extract[BaseClass], but I'm getting "MappingException: Parsed JSON values do not match with class constructor".
wondering if anybody can point me in the right direction on something: i have some input that is coming from a mongo source, and there are idiosyncracies that i'm having to handle. one of these is that i get fields in the bson dot notation that really are supposed to be nested json objects. e.g. {"foo.bar":false}. i've add some custom field serializers to turn this into proper documents {"foo":{"bar":5}} but i've just found out that i can possibly get updates to the same nested document {"foo.bar": false, "foo.bash": true} my question is, where would i even look to add something to merge objects like this? i was thinking org.json4s.Extraction might have it
Filippo De Luca

Guys I am writing a custom serializer that need to use another one:

case object TimeWindowFormats extends CustomSerializer[OpeningMeterReadingTimeWindow](format => (
    case obj: JObject =>
      OpeningMeterReadingTimeWindow.Defined((obj \ "from").extract[Instant], (obj \ "to").extract[Instant])
    case JNull => OpeningMeterReadingTimeWindow.Undefined
    case defined: OpeningMeterReadingTimeWindow.Defined =>
      ("from" -> defined.from) ~ ("to" -> defined.to)
    case OpeningMeterReadingTimeWindow.Undefined => JNull

this does not compile as defined.from and defined.to are java.time.Instant

How can I reuse or assume the formats contains the serializer for Instant?
Filippo De Luca
Can I use decompose?
I'm having trouble running the benchmarks.
/code > json4s-benchmark/runMain org.json4s.benchmark.Runner
[info] Running json4s-benchmark org.json4s.benchmark.Runner
[error] Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.io.Closeables.closeQuietly(Ljava/io/Closeable;)V
[error] at com.google.caliper.Runner.measure(Runner.java:301)
[error] at com.google.caliper.Runner.runScenario(Runner.java:229)
[error] at com.google.caliper.Runner.runOutOfProcess(Runner.java:378)
[error] at com.google.caliper.Runner.run(Runner.java:97)
[error] at com.google.caliper.Runner.main(Runner.java:423)
[error] at com.google.caliper.Runner.main(Runner.java:436)
[error] at org.json4s.benchmark.Runner$.main(Runner.scala:7)
[error] at org.json4s.benchmark.Runner.main(Runner.scala)
[info] 0% Scenario{vm=java, trial=0, benchmark=JacksonFullCircle}
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last json4s-benchmark/compile:runMain for the full output.
[error] (json4s-benchmark/compile:runMain) Nonzero exit code returned from runner: 1
[error] Total time: 3 s, completed May 26, 2017 10:37:12 AM
Looks like something with Guava versions maybe?
I do not undertand this error at all... construction cannot continue: "org.json4s.JsonAST$JNothing$ cannot be cast to org.json4s.JsonAST$JObject" (IP2GeoTestSuite.scala:50)
Hi, I'm new to this so I'm not sure if just asking a question is the appropriate approach, but here it goes...I'm having problems testing case class equality after extraction. I found a similar stack overflow question: https://stackoverflow.com/questions/41100738/json4s-breaks-case-class-eqality but it was never answered. I've tried stepping through the debugger but I seem to always get lost. I've been unable to step through the 'equals' or '==' methods of the two objects and when comparing the object fields separately everything is the same. I then thought it had something to do with the class interfaces, like maybe an interface was lost during extraction, but the returned object is still a Product and has all of the same classes as an originally built object. Any help is greatly appreciated! Thank you.
Joshua E. Jodesty
how do i write json file with json4s?
Alexander Bjerkan
Is it possible to create a custom serializer for Option[String]?
In the case of empty strings, I want it to be deserialized into None instead of ending up as Option("")
Jason Dusek
Consider a file structured like { "Records": [ {Object}, {Object}, ...thousands of objects... ] }
For each {Object} it would be nice to use the AST; but one would like to use the pull-parser to step past "Records" and stream each {Object}.
Is there a way to reform an AST "thing" from pull parser tokens?