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
0 answers

Using Scala's Json4s with Java

I have a JAR that contains the following Scala class: class JsonAvroConverter(val sch : org.apache.avro.Schema) extends scala.AnyRef { def toJson(avroData : org.json4s.JValue) : org.json4s.JValue = { /* compiled code */ } } Now I need to be able…
summerNight
  • 1,446
  • 3
  • 25
  • 52
0
votes
1 answer

Scala Parsing a json record coming from kafka

I'm using Spark Streaming with Scala and I'm getting json records from kafka. I would like to parse it so I can get the values (dateTime and quality) and process. Here is my code : stream.foreachRDD(rdd => { rdd.collect().foreach(i => …
AsmaaM
  • 63
  • 2
  • 3
  • 12
0
votes
1 answer

Is there an out of the box way to parse a list of 2-tuples with json4s?

Given: implicit val formats = DefaultFormats val json = """[ {"myType":"type1","things":["1","2","3","4","5","6"]}, {"myType":"type1","things":["1","2","3","4","5","6"]} ]""" case class Stuff(myType: String, things:…
Don Branson
  • 13,631
  • 10
  • 59
  • 101
0
votes
0 answers

Extract list of fields from Nested Json using Json4s Scala

I am trying to parse the nested Json and get the list of name from the fields tag. { "subject": "table-name", "version": 1, "id": 234, "schema": "{ \"type\":\"record\",\"name\":\"table-name\", \"fields\":[ …
Explorer
  • 1,491
  • 4
  • 26
  • 67
0
votes
1 answer

Scala: Task not serializable in RDD map Caused by json4s "implicit val formats = DefaultFormats"

The following program tries to invoke 3 functions for every ROW(in RDD map): import org.json4s._ import org.json4s.jackson.JsonMethods._ implicit val formats = DefaultFormats class TagCalculation extends Serializable { def…
meng
  • 53
  • 10
0
votes
1 answer

Scala deserializing JSON with json4s issue

when I am deserializing a JSON with the following simple code usign json4s package main.scala import org.json4s._ import org.json4s.jackson.JsonMethods._ object Main { case class Person(name: String, age: Int) def main(args:…
flavio
  • 168
  • 1
  • 9
0
votes
1 answer

With lift-json or json4s how can I map fields of Option[String] to None in the case of empty string?

This test should explain what I'm trying to do, thanks: import com.typesafe.scalalogging.StrictLogging import net.liftweb.json._ import org.specs2.mutable.Specification object Dummy { case class Person(first: String, last: String, job:…
jpswain
  • 14,642
  • 8
  • 58
  • 63
0
votes
2 answers

Parsing JObject for key and values with json4s-jackson

How can I get the keys scenario0 and scenario1 for each JObject in my List? poop is a: poop: List[org.json4s.JsonAST.JValue] = List(JObject(List((street,JString(Bulevard)), (city,JString(Helsinki)))), JObject(List((street,JString(Bulevard)),…
Liondancer
  • 15,721
  • 51
  • 149
  • 255
0
votes
1 answer

json4s JValue expected (String,String) given

Using Scala and json4s (Maybe Im missing a golden fish library or something) I am trying to add some list (or array) of strings to a JSON so in the end looks like: {"already":"here",..."listToAdd":["a","b",c"]} The fact is that I already have the…
ppanero
  • 327
  • 5
  • 17
0
votes
0 answers

Json4s parse JSON string error

I have the following piece of code: def fromString[T <: AnyRef](str: String)(implicit m: Manifest[T]): T = { val json = parse(str) json.extract[T](formats,m) } I also have a case class that is defined as such: case class Points(pts:…
0
votes
1 answer

Json4s casting error during string parsing

final case class Stuff(metadata: Option[String]) { val metadataJson: JObject = parse(metadata.getOrElse("{}")).asInstanceOf[JObject] } This throws a type mismatch error found: Object required: JsonInput But it shouldnt happen since…
fuzzycuffs
  • 139
  • 1
  • 15
0
votes
1 answer

Json4s: Decomposing to JValue gives ArrayIndexOutOfBoundsException

I am using Extraction.decompose to produce a JValue and it is intermittently failing. I am asking it to decompose a Seq of the following case class: case class Item(locators: Seq[String], dateAdded: DateTime = new DateTime(0L),…
Paul L.
  • 3
  • 1
0
votes
1 answer

Handle JSON data in POST request using json4s

I'm trying to map JSON i/p to my case class CacheRequest. request is POST. I'm new to Scala and Akka. import org.json4s.{DefaultFormats, Formats} implicit val formats: Formats = DefaultFormats val route: Route = traceContextAwareRoute { …
Raj Parekh
  • 192
  • 1
  • 9
0
votes
2 answers

How to get the failure that happens in another class scope in my test?

I have a function in my service that takes some jvalue data, extract it and return some model. def getInstanceOf(data: JValue, aType: String): Living = aType match { case "person" => data.extract[Person] case "animal" =>…
jack miao
  • 1,398
  • 1
  • 16
  • 32
0
votes
1 answer

JSON4S deserialization without parameter name

I have the following use-case: Each class that I'm serde using JSON4S have a field, named ID. This ID can be any type T <: Stringifiable, where Stringifiable requires your ID type to be hashed to a string. Stringifiables also have constructors that…
Dyin
  • 5,815
  • 8
  • 44
  • 69