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

How to let json4s or other scala json libs generate Java Collections

Background: I use some Java libs which require Java Collections (java.util.ArrayList etc.) Input JSON items are dynamic, so I can only use Map[String, Any] as the result type to json4s' extract method (viz. parse(json).extract[Map[String,…
Tonny Tc
  • 852
  • 1
  • 12
  • 37
0
votes
2 answers

Merge multiple value in Json

I'm working with this kind of Json in Scala : { "ClientBase": [ { "string#name": "robert", "int#age": 46, "string#country": "USA" }, { "string#name": "tom", "int#age":…
0
votes
1 answer

How to serialize sealed abstract class with Json4s in Scala?

How do i serialize a sealed abstract class with Json4s in Scala? The following classes are defined: sealed abstract class Person extends Product with Serializable case class Spouse(name: String, age: Int) extends Person case class Customer(name:…
0
votes
1 answer

How to Convert JSONString to JSONArray using Json4s

I am trying to convert the JSONString value to the JSONArray for further processing. Currently my JSONString value comes as ["a","b","c","d"] now all I need is to convert this JSONString to JSON Array so that I can easily iterate over the…
Vishal
  • 1,442
  • 3
  • 29
  • 48
0
votes
1 answer

JSON to case class with generics decoding with json4s

I'm trying to build a json to case class en/decoder using json4s Using generics icw Manifest seems to work for ordinary types/classes, but more complex configs seem to fail. How can I use json4s combined with extracting more complex types from json…
Tom Lous
  • 2,819
  • 2
  • 25
  • 46
0
votes
2 answers

is it possible to decode JSON into ListMap using Json4s

The result of Json4s decoding frequently scramble the sequence of element in a JObject if decoding into a HashMap, so I tried to decode into ListMap instead. However, there seems to be no way of doing this, when I run the following simple…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
0
votes
2 answers

json4s is faling with NPE, what can be the proper format for nested json

var json= {"a1":"b","c1":"d","e1":{"f1":"g","h1":"i","j1":"k"}} implicit val formats = org.json4s.DefaultFormats parse(json).extract[Map[String, String]] I am getting NullPointerException when i execute the code. The NPE is because formats is…
sailor
  • 753
  • 1
  • 6
  • 17
0
votes
1 answer

How to create generic JSON serializer/deserializer in Scala?

I wanted to serialize and deserialize some case classes and realized I was repeating code. Unfortunately I cannot figure out a way to keep things DRY. Hoping someone can provide some assistance. Below I will provide a sample problem that is not…
Miles
  • 189
  • 2
  • 13
0
votes
1 answer

HTTP response parsing: Seq vs Set conventions

I'm calling an API using Akka-HTTP and Json4s, but the question could apply for any HTTP client/JSON parser. The API returns a short collection of items, should I use Seq or Set when parsing a response? Due to the small size of the collection,…
EugeneMi
  • 3,475
  • 3
  • 38
  • 57
0
votes
1 answer

Json4s alternative api with scala generics / type members

I know there is an xpath like api to get fields out of a JObject in Json4s val x = (obj \ "Type").asInstanceOf[JString].values However it feels a bit cumbersome and I'm not a fan of symbolic like apis. I kind of want something like this: implicit…
Luke De Feo
  • 2,025
  • 3
  • 22
  • 40
0
votes
2 answers

How can I serialize Sangria responses with json4s and Akka HTTP?

I'm working through a slight variation of Sangria's Getting Started, using Akka HTTP. I'm attempting to use json4s-jackson as the serializaltion lib, but am running in to some trouble getting the response I want. Specifically, the serialized…
David van Geest
  • 1,957
  • 1
  • 20
  • 19
0
votes
1 answer

json4s JValue scala classTag works wrong

In my code, I use classTag[JValue] want to get org.json4s.JsonAST.JValue , but actually it returns org.json4s.JsonAST$JValue, it is strange ! why there is the $? I am new guy use scala ,could someone answer me ? thanks a lot
yang_song
  • 24
  • 3
0
votes
1 answer

not able to serialize scala class using genson

I have a problem where i can't get toJson to work with Scala classes. It outputs an empty json string. : {} The classes have their member variables populated. I tried both a custom genson class and the default genson class. Both yield the same…
K_U
  • 15,832
  • 8
  • 26
  • 29
0
votes
1 answer

Deserialize BigDecimal in scala with json4s return empty list

Given this json: { "id": "1", "details": [{ "tax": [{ "amount": 1 }, { "amount": 2 }] }] } I'm trying to reading it in this way: lazy val amounts: List[BigDecimal] = parse(json) \\…
Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57
0
votes
2 answers

JSONPath and json4s

I need to extract a field value from the message: { "data": { "code": "404", ... } } JSONPath expression is stored in a variable: val path = "/data/code" I'm using json4s for manipulating JSON. From the doc, one can achieve this using…
Aliaxander
  • 2,547
  • 4
  • 20
  • 45