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

Using Argonaut to create generic JSON converter

I'm new to Scala, and here I'm trying to create a generic json converter based on Argonaut. I've tried to search on google and stackoverflow, but so far I have no clue. Here is the snippet of my code. import…
Wins
  • 3,420
  • 4
  • 36
  • 70
3
votes
1 answer

Argonaut: decoding a polymorphic array

The JSON object for which I'm trying to write a DecodeJson[T] contains an array of different "types" (meaning the JSON structure of its elements is varying). The only common feature is the type field which can be used to distinguish between the…
ceran
  • 1,392
  • 1
  • 17
  • 43
3
votes
1 answer

Decoding into recursive ADTs with argonaut

I'm trying to parse json like { "element": "string", "content": "application/json" } where element decides which type the json is. But my code fails to parse. http://scastie.org/15213 import scalaz._, Scalaz._ import argonaut._, Argonaut._,…
Reactormonk
  • 21,472
  • 14
  • 74
  • 123
3
votes
1 answer

Scala argonaut encode a jEmtpyObject to 'false' rather than 'null'

Im dealing with some code outside of my immediate control, where I need to encode an option[Thing] where the case is as per normal if Thing exists, however the None case must return 'false' rather than null. Can this be accomplished easily? I'm…
Josh
  • 145
  • 1
  • 10
3
votes
1 answer

How to use argonaut to parse an optional custom field?

I defined a user which has a "video" information: case class User(name:String, video: Option[Video]) case class Video(title:String, url:String) And we have such a json: { "name": "somename", "video": { "title": "my-video", …
Freewind
  • 193,756
  • 157
  • 432
  • 708
3
votes
0 answers

Is there any simpler approach to provided a default value for un-suppiled or blank string field when parsing JSON with argonaut?

I'm using Argonaut to parse JSON strings. There is a requirement: If any field is not provided, or is empty or blank, give it the string "not supplied" instead. I have a solution, but it seems very complicated: case class User(name: String, home:…
Freewind
  • 193,756
  • 157
  • 432
  • 708
3
votes
1 answer

Is there a more concise way to remove a top level JSON property using Argonaut?

Let's say I have this little Argonaut Json instance: import argonaut._, Argonaut._ Json.obj( "id" := 42, "viewed" := false ) Now, I want to remove the pair whose key is viewed. I found the following to work, but it's a bit too verbose. Is…
Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
2
votes
1 answer

Decoding Json with Circe when fields are incomplete

I have a transcript in json format with a bunch of words in it { "words": [{ "duration": 123, "name": "world" "time": 234, "speaker": null }] } I have been using Circe to encode/decode Json. In…
Alberto Centelles
  • 1,215
  • 11
  • 24
2
votes
1 answer

Sending an http response with Json content using marshallers in Akka Http

I want to send a Http error response with a message in JSON format in the body. I am having trouble using the PredefinedToResponseMarshallers. I saw an implementation in the Akka docs but I tried a similar thing and it throws a compilation…
Sudhanshu
  • 125
  • 6
2
votes
0 answers

Retrieving Traversed JSON Fields

Given: import argonaut._ import Argonaut._ def f(c: HCursor): Option[CursorHistory] = (c --\ "foo").hcursor.map(_.history) scala> val json = Parse.parse("""{"foo" : 42}""") json: Either[String,argonaut.Json] = Right({"foo":42}) scala>…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
2 answers

Decode w/ History on Success?

Given: import argonaut._, Argonaut._ case class Person(name: String) implicit def decode: DecodeJson[Person] = DecodeJson ( c => for { name <- (c --\ "name").as[String] } yield Person(name) ) scala>…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Purescript Reuse Argonaut JSON Decoding for Affjax Respondeable

I'm trying to fetch some JSON data from a Haskell server, but I'm having trouble with the Respondeable instance, as well as just Affjax in general. I've defined EncodeJson + DecodeJson with Data.Argonaut.Generic.Aeson (GA), but I can't figure out…
sportanova
  • 125
  • 3
  • 8
2
votes
1 answer

How to modify value and type in JSON using argonaut lens?

Assume the following simple JSON document: { "key" : "val1" } I'd like to update the value of "key" but at the same time also change its type, so from string change it to an int. Now, using an HCursor like below it is…
cpard
  • 330
  • 1
  • 7
2
votes
2 answers

parse recursively nested Json structure with Play framework

we are using Play framework 2.3.4. From one of the APIs we make a web service call to a third party service - structure of the returned response is dynamic and may change. Only sub-structure that's static within the response JSON is a particular…
user2066049
  • 1,371
  • 1
  • 12
  • 26
2
votes
1 answer

Parsing stream of JSON with Argonaut

I'm using Argonaut to parse objects from a remote JSON provider. The API has two types of endpoints, one is a traditional REST request at a URL and the response of a single JSON object. I am able to easily parse complex JSON return objects with…
Brian Topping
  • 3,235
  • 28
  • 33