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

How to write JsValue?

I have a case class like this: case class BadResponse(message:String,errorCode:Integer,errors:Option[JsValue]) it seem that json4s write does not understand…
mmdc
  • 1,677
  • 3
  • 20
  • 32
0
votes
2 answers

get Json head node value in Scala

I'm a beginner of Scala and using lib "json4s" for JSON parsing, and I have JSON data formatted like below: scala> val str = """ | { | "index_key": { | "time":"12938473", | "event_detail": { | …
keypoint
  • 2,268
  • 4
  • 31
  • 59
0
votes
1 answer

use Scala to get JSON data in lower levels

I'm a beginner of Scala, and I have JSON data formatted like below: { "index_key": { "time":"12938473", "event_detail": { "event_name":"click", "location":"US" } } } I'm trying to get the…
keypoint
  • 2,268
  • 4
  • 31
  • 59
0
votes
1 answer

Consuming and API with Scala Dispatch Same method two different JSON

I 'm consuming a REST API, When the call goes OK, this API return a 200 OK Header, Then in the body it can handle two different JSONs {"Error": { "code" = 1 "msg" = "some error message" } } Or if the data send was correct, it…
anquegi
  • 11,125
  • 4
  • 51
  • 67
0
votes
0 answers

How to convert List of Lists in Scala json4s

I have trouble to convert scala struct to json. I use library json4s. val asanaList = Seq(("007", 536), ("008", 888)) println(compact(render(asanaList))) The result is: [{"007":536},{"008":888}] I need something…
Sol
  • 320
  • 2
  • 8
0
votes
0 answers

scala json4s handling null values

I have a case class case class Test(a: String, b: Option[Double]) object TestSerializer extends CustomSerializer[Test] (format => ({ case jv: JValue => val a = (jv \ "a").extract[String] val b = (jv \ "b").extractOpt Test(a, b) },{ case…
rreiki
  • 73
  • 3
0
votes
1 answer

What's the common practice to describe relative time in JSON

I'm designing a JSON format for my RESTful service, and want to find a good way to express relative time. For example: 1 minutes, 2 hours, 3 days, 4 weeks, 5 years And come up: {"interval": 1, "unit": "day"}, are there better ways to express this?
yjshen
  • 6,583
  • 3
  • 31
  • 40
0
votes
1 answer

json4s xpath report java.lang.NoSuchMethodError

I followed the example from "XPath + HOFs" part of https://github.com/json4s/json4s, below is my source code: import org.json4s._ import org.json4s.native.JsonMethods._ object HiveToCSVEngine { def main(args: Array[String]): Unit = { val json…
Guocheng
  • 543
  • 3
  • 15
0
votes
2 answers

Json4s date to unixtimestamp

How to create wrapper for Json4s? Default json4s formater date converted all to SimpleDateFormat. I want convert all date field to unixtime format.
Rinat Mukhamedgaliev
  • 5,401
  • 8
  • 41
  • 59
0
votes
1 answer

how to generate empty array in json4s?

I've 2 bits of scala code using the json4s dsl to produce json content val feastWithMenus = "Feast" -> ("target" -> "me") ~ ("menus" -> List( ("first" -> "pate") ~ ("mains" -> "beef") ~ ("dessert" -> "ice-cream") , ("first"…
Tim Pigden
  • 895
  • 2
  • 9
  • 18
0
votes
0 answers

Scala generic function fill type dynamicaly

I am using a org.json4s for json read and write. The library containa method like this. val ser = read[ContentObject](jsonString) But,, i want to do something like. val c = Class.forName(r.e) val e = read[Login](URLDecoder.decode(r.c)) Because the…
Jeff Lee
  • 35
  • 7
0
votes
1 answer

Json4s: Trouble while trying to convert Json attribute to java.sql.Date

I am using Json4s to deserialize json messages. I have a case class like case class A(id: Int, b: Option[java.sql.Date]) Whenever I try to convert a json message to case class A, I get none as the value of b scala>…
mohit
  • 4,968
  • 1
  • 22
  • 39
0
votes
1 answer

Lift JSON JValue Extract issue

import net.liftweb.json._ import net.liftweb.json.JsonAST._ import net.liftweb.json.Extraction._ import net.liftweb.json.Printer._ implicit val formats = net.liftweb.json.DefaultFormats val jV =…
user2780187
  • 677
  • 7
  • 16
0
votes
1 answer

json4s serializes a case class Test("test") to "{}" on Android

I'm serializing a case class graph to JSON in an Android Scala app (using "com.hanhuy.sbt" % "android-sdk-plugin" % "1.3.5"). I'm using "org.json4s" %% "json4s-native" % "3.2.10", and it fails even with a simple case class which looks like…
John M
  • 1,469
  • 17
  • 41
0
votes
2 answers

Strange behaviour of Scala for-comprehension and json4s

The code below should: iterate over a sequence of strings parse each one as json, filter out fields whose names could not be used as an identifier in most languages lowercase the rmaining names serialize the result as a string It behaves as…
Daniel Mahler
  • 7,653
  • 5
  • 51
  • 90
1 2 3
29
30