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
3
votes
1 answer

scala json4s how can i extract field by condition

I've got json(for example): { "name": "", "count": 2, "children": { "app_open": { "name": "app_open", "count": 1, "children": { "session_end": { "name": "session_end", "count": 1, …
ANTVirGEO
  • 124
  • 1
  • 16
3
votes
1 answer

Using json4s-native library in a Spark cluster

I am trying to process data in an AWS EMR Spark cluster. For that, I have a Scala application which reads in raw JSON data from S3, parses it to Map[String, Any] with Scala's native scala.util.parsing.json.JSON library and parseFull method. Then I…
V. Samma
  • 2,558
  • 8
  • 30
  • 34
3
votes
0 answers

How can I serialize/deserialize JSR310 classes using json4s and Jackson?

I have a case class: case class Stuff(createdOn: Instant) and I'm using json4s with Jackson to provide my JSON serialization/deserialization. However, I'm not able to serialize/deserialize createdOn properly. If I was using plain Jackson,…
manub
  • 3,990
  • 2
  • 24
  • 33
3
votes
2 answers

extracting keys from json string using json4s

can someone tell me how to extract keys from json using json4s. My use case: json stored as string in scala variable: { "key1" : "val1", "key2" : ["12", "32"], "key3" : {"keyN" : "valN"} } I'd like to transform this into a following…
homar
  • 575
  • 1
  • 7
  • 19
3
votes
0 answers

Different results in IntelliJ scala worksheet and console

I'm trying to parse jsons with following code: import java.text.SimpleDateFormat import org.json4s._ import org.json4s.ext.EnumNameSerializer import org.json4s.native.JsonMethods._ object Area extends Enumeration { type Area = Value val grid,…
langusta
  • 368
  • 2
  • 7
3
votes
2 answers

Parsing null values in JSON using json4s

I'm using json4s library in my project to manually parse JSON field by field (without automatic deserializing it to case classes). For example I have following JSON: { result: "OK", persons: [ {name: "Alex"}, {name: null} ] } And…
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
3
votes
2 answers

How to disallow null as a value in json4s deserialization

I'm deserializing data from json into case classes and just came across some malformed json providing me null for a non-optional object. I would prefer this to be parser failure, instead of setting the field value to null. That way i could safely…
Arne Claassen
  • 14,088
  • 5
  • 67
  • 106
3
votes
2 answers

What's the most elegant way to deconstruct a JSON array with JSON4s?

I have to deconstruct the following JSON into a list of case classes: { "data": [ [49, true, 14, null, null], [52, false, null, null, null], [72, true, 4, 2, 1] ] } case class: case class Data(i1: Int, b: Bool, i2: Option[Int], i3:…
Michael Rueegg
  • 765
  • 4
  • 13
3
votes
1 answer

convert scala object to json using json4s

I have an ordinary scala class not a case class with many member variables including Buffers, Lists etc. I want to override the toString method of the class to give a json-string just like javascript's json.stringify() does. Is this possible with…
Vikash Balasubramanian
  • 2,921
  • 3
  • 33
  • 74
3
votes
0 answers

When I convert an object to json with json4s in a SBT task, it reports errors, how to fix?

I'm writing a SBT task, which will convert some objects to json and output, but has errors. Code is: project/plugins.sbt libraryDependencies ++= Seq( "org.scala-lang" % "scalap" % "2.10.4", "org.json4s" %% "json4s-native" % "3.2.6", …
Freewind
  • 193,756
  • 157
  • 432
  • 708
3
votes
0 answers

JSON4s can't find constructor w/spark

I've run into an issue with attempting to parse json in my spark job. I'm using spark 1.1.0, json4s, and the Cassandra Spark Connector, with DSE 4.6. The exception thrown is: org.json4s.package$MappingException: Can't find constructor for…
worker1138
  • 2,071
  • 5
  • 29
  • 36
3
votes
1 answer

Deserialize json without name

I'm Scala na json4s to consume json. To deserialize I'm calling org.json4s.native.JsonMethods.parse and ExtractableJsonAstNode.extract method. This is a part of json file: "": { "atribute1": "v1", "instanceId": "i", }, It…
KrzyH
  • 4,256
  • 1
  • 31
  • 43
3
votes
2 answers

TransformField in JArray with json4s

I'm giving Scala a try, and in particular the json4s lib in order to manipulate some json. I'm having a hard time with the syntax of both Scala and json4s, thought I'd ask you guys. I have this json, which I need to update some fields on, and send…
Stefan Konno
  • 1,337
  • 2
  • 16
  • 28
3
votes
1 answer

Json4s ignoring None fields during seriallization (instead of using 'null')

I am having a generic json serialization method that uses json4s. Unfortunately, it is ignoring fields if the value is None. My goal is to have None fields be represented with a null value. I tried by adding custom serializer for None, but still it…
Yadu Krishnan
  • 3,492
  • 5
  • 41
  • 80
3
votes
1 answer

Is it possible to serialize non case classes in Scala?

Is it possible to serialize object of below class using Json4s or lift or any other library? class User(uId: Int) extends Serializable { var id: Int = uId var active: Boolean = false var numTweets: Int = 0 var followers: ArrayBuffer[Int] =…
alchemist
  • 41
  • 4