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

Can I make json4s's extract method case insensitive?

I am using case classes to extract json with json4s's extract method. Unfortunately, the Natural Earth source data I am using isn't consistent about casing... at some resolutions a field is called iso_a2 and at some it's ISO_A2. I can only make…
Mohan
  • 7,302
  • 5
  • 32
  • 55
0
votes
1 answer

Reverse operation of extract (json4s)

json4s allows user to convert a JsonAST object to a case class using extract. import org.json4s._ import org.json4s.jackson.JsonMethods._ implicit val formats = DefaultFormats case class Item(name: String, price: Double) val json =…
yiksanchan
  • 1,890
  • 1
  • 13
  • 37
0
votes
2 answers

Scala case class whose fields can be mandatory and optional at different instances

I've created two rest end-points in akka http which takes string as input, parse it using Json4s and then do processing on it. My case class is like - final case class A(id: String, name: String, address: String) 1st end point receives only id…
Ishan
  • 996
  • 3
  • 13
  • 34
0
votes
1 answer

Merging/ Combining JSON on duplicate nodes using JSON4S

Before any one marks this as duplicate, i've already checked this question: Remove duplicates and merge JSON objects. (copied example from there) I'm working in on a case that involves merging json like in the example below, [{ "id" : 1, …
Chitral Verma
  • 2,695
  • 1
  • 17
  • 29
0
votes
1 answer

scala - How to parse JSON string into separate records?

I wrote a method to concatenate JSON values. def mergeSales(storeJValue: JValue): String = { val salesJValue: JValue = parse(rawJson) val store = compact(render(storeJValue)) val sales = compact(render(salesJValue)) val…
samba
  • 2,821
  • 6
  • 30
  • 85
0
votes
0 answers

Flat nested JSON to header level using scala

Below is my sample JSON and can be nested to any level deep: { "key1": { "keyA": 'valueI' }, "key2": { "keyB": 'valueII' }, "key3": [ { "a":1, "b":2 }, { "a":1, "b":2 } …
Naman Agarwal
  • 614
  • 1
  • 8
  • 28
0
votes
1 answer

How to convert json to string with escape characters using json4s

I am trying to create a JSON which will have strings as values. One of the element will have JSON in String format as values Eg: input: {"foo":"bar","nestedFoo":[{"foo":"bar"}]} output: {"foo" : "bar",…
Srini
  • 3,334
  • 6
  • 29
  • 64
0
votes
0 answers

Cant get json4s data extraction to work

Im working on a project that has scala backend and scalatra as a servlet. For now, the backend is running inside a Vagrant box, and sbt is used to build the program. My problem is that I need to handle incoming Json-formatted data, but I cant…
0
votes
1 answer

How to decode a Json with a root array?

I'm having some trouble figuring out how to decode a json with a root array into a case class using json4s-jackson library. The purpose of extracting directly into a case-class and not into a Seq[Username] is to validate the existence of a single…
Dmitry
  • 778
  • 8
  • 10
0
votes
2 answers

json4s - Partially deserialize to a case class

I have this JSON object { "name": "Chaitanya", "addresses": [ { "street": "20 ABC", "apt": "10" }, { "street": "10 XYZ", "apt": "D3" } ] } Which I'm trying to deserialize into a following case class: case class Person( name:…
Chaitanya Chandurkar
  • 2,142
  • 3
  • 24
  • 43
0
votes
1 answer

Json4s: keep unknown fields in a map when deserialising

I am trying to parse the response given by a HTTP endpoint using json4s in scala. The Json returned could have many number of fields (They are all documented and defined, but there are a lot of them, and they are subject to change.) I don't need to…
smur89
  • 329
  • 1
  • 3
  • 15
0
votes
1 answer

How do I serialize one field "preservingEmptyValues" to null using json4s

I am using json4s. I am aware that you can "preserve None values" of all Option members in a type using DefaultFormats.preservingEmptyValues. This has an output like so: scala case class MyType(a: Option[String], b: Option[Int], c:…
Rhys Bradbury
  • 1,699
  • 13
  • 24
0
votes
1 answer

How do I handle undefined class objects passed as function arguments?

The variable entered as a function parameter is an instance of the case class. In this situation, can you do something like JsonMethods.extract [variable]? // I do not know if the "Any" keyword is appropriate. Or, Class [_]? def func(a: Any)…
Dogil
  • 107
  • 1
  • 17
0
votes
1 answer

Create a json deserializer and use it

How do you create a jackson custom serializer and use it in your program? The serializer is used to serialize data from a kafka stream, because my job fails if it encounters a null. I tried the following to create a serializer. import…
Srinivas
  • 2,010
  • 7
  • 26
  • 51
0
votes
1 answer

Accessing attributes in objects Scala

An example of the sort of objects I need to grab from my json can be found in the following example(src): { "test": { "attra": "2017-10-12T11:17:52.971Z", "attrb": "2017-10-12T11:20:58.374Z" }, "dummyCheck": false, "type": "object", …
Curious_Bop
  • 311
  • 2
  • 8
  • 20