Questions tagged [argonaut]

Argonaut is a JSON library for Scala, providing a rich library for parsing, printing and manipulation as well as convenient codecs for translation to and from scala data types.

About

Argonaut is a JSON library for Scala, providing a rich library for parsing, printing and manipulation as well as convenient codecs for translation to and from scala data types.

Argonaut is licenced under BSD3 (see LICENCE).

Links

88 questions
71
votes
1 answer

What are the problems with an ADT encoding that associates types with data constructors? (Such as Scala.)

In Scala, algebraic data types are encoded as sealed one-level type hierarchies. Example: -- Haskell data Positioning a = Append | AppendIf (a -> Bool) | Explicit ([a] -> [a]) // Scala sealed trait…
missingfaktor
  • 90,905
  • 62
  • 285
  • 365
14
votes
1 answer

Cannot find an implicit ExecutionContext. You might pass spray scala

I have this two erros: Error:(39, 20) Cannot find an implicit ExecutionContext. You might pass an (implicit ec: ExecutionContext) parameter to your method or import scala.concurrent.ExecutionContext.Implicits.global. val pipeline = sendReceive …
kam kimo
  • 193
  • 1
  • 2
  • 7
11
votes
2 answers

Update case class from incomplete JSON with Argonaut or Circe

I need to create an updated instance from a case class instance (with any needed DecodeJsons implicitly derived), given an incomplete json (some fields missing). How can this be accomplished with Argonaut (preferably) or Circe (if I have…
eirirlar
  • 814
  • 6
  • 24
9
votes
2 answers

Encoding nested classes using scala argonaut

I'm trying to encode/decode following case class case class Person(name: String, age: Int, childs: List[Person]) using the following code: object Person { implicit def PersonCodecJson = casecodec3(Person.apply, Person.unapply)("name",…
Daniel
  • 91
  • 4
7
votes
3 answers

Parse JSON array using Scala Argonaut

I'm using Scala & Argonaut, trying to parse the following JSON: [ { "name": "apple", "type": "fruit", "size": 3 }, { "name": "jam", "type": "condiment", "size": 5 }, { …
Gilbert
  • 3,584
  • 2
  • 26
  • 30
6
votes
0 answers

Argonaut CodecJson and decoding subtypes

In the Argonaut DecodeJson trait there is a method ||| for chaining together decoders, so that the first succeeding decoder is chosen. There is also a similar method in DecodeResult which has the same effect. It looks at first glance as though one…
Robin Green
  • 32,079
  • 16
  • 104
  • 187
5
votes
0 answers

How to write a Scala Argonaut codec for all Java enums

I have a Scala project that uses a bunch of Java code, for example this Java source: public enum Category { FOO, BAR }; I then have a bunch of Scala case classes that I serialise to and from JSON using Argonaut like this: case class Thing (a:…
sungiant
  • 3,152
  • 5
  • 32
  • 49
4
votes
1 answer

Collecting Elements in a JSON Array

I having big toruble with Argonaut. I am needing to collect all elements in JSON array. For example, I having this data in JSON. val data = """{"id": 1, "items": [{"name": "foo","price": 10},{"name": "bar","price": 20}]}""" Then I am needing to…
Mojo
  • 1,152
  • 1
  • 8
  • 16
4
votes
1 answer

`circe` Type-level Json => A Function?

Using circe or argonaut, how can I write a Json => A (note - Json may not be the name of the type) where A is given by the SSN class: // A USA Social Security Number has exactly 8 digits. case class SSN(value: Sized[List[Nat],…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
4
votes
1 answer

How to remove keys with null values from Argonaut Json objects

How can an extension method be written to remove all keys with a null value from an Argonaut Json object: I tried this: package object Extensions { implicit class JsonExtensions(val json: Json) extends AnyVal { def removeNulls: Json = { …
sungiant
  • 3,152
  • 5
  • 32
  • 49
4
votes
1 answer

Decode single field of object in a json array with argonaut/circe

Suppose I have such json { "sha": "some sha", "parents": [{ "url": "some url", "sha": "some parent sha" }] } and such case class case class Commit(sha: String, parentShas: List[String]) In play-json I could write the reads like…
Tao Yang
  • 115
  • 1
  • 8
4
votes
2 answers

Mapping over a JSON array with Argonaut

I'm having a hard time slogging through the Argonaut documentation, so I figured I'd just ask for a simple example. val input = """{"a":[{"b":4},{"b":5}]}""" val output = ??? // desired value: List(4, 5) I can get a cursor down to the…
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
4
votes
1 answer

creating Writeable[Argonaut.Json] for play framework http response

I am trying to change the implementation of this function from using plays json library like so def apply[T](action: => ApiResponse[T])(implicit tjs: Writes[T], ec: ExecutionContext): Future[Result] = { action.fold( err => …
Mark
  • 3,137
  • 4
  • 39
  • 76
4
votes
1 answer

How to ignore an item when generating the json string if the value is None?

I'm trying to use Argonaut to generate JSON string from a Scala instance. import argonaut._, Argonaut._ case class Person(name: Option[String], age: Int, things: List[String]) implicit def PersonCodecJson = casecodec3(Person.apply,…
Freewind
  • 193,756
  • 157
  • 432
  • 708
4
votes
2 answers

Converting JSON field names in argonaut

I'm writing a library to convert JSON responses from an API for backwards compatibility reasons. And what I need to do is take in arbitrary JSON, and change certain field names. I'm using scala and argonaut, but I don't see any way in the docs or…
Falmarri
  • 47,727
  • 41
  • 151
  • 191
1
2 3 4 5 6