0

The JSON documents I'm creating need to have a properties field, even if there are no properties.

{"foo":"bar","properties":{}} is legal, {"foo":"bar"} is illegal.

How can I define an empty object to use as the properties value using the Json4s DSL?

("foo" -> "bar") ~ ("properties" -> ???)

I have tried Map.empty, new Object, (). All of these are not the correct type.

Synesso
  • 37,610
  • 35
  • 136
  • 207

1 Answers1

0

I never used Json4s, but it seemed to work with:

val map = ("foo" -> "bar") ~ ("properties" -> Nil)

Here is my full code:

  import org.json4s._
  import org.json4s.native.JsonMethods._
  import org.json4s.JsonDSL._

  val map = ("foo" -> "bar") ~ ("properties" -> Nil)

  println(compact(render(map)))
Daniel Hinojosa
  • 972
  • 5
  • 9