Questions tagged [aeson]

A Haskell JSON parsing and encoding library optimized for high performance and easy usage

Aeson is a Haskell JSON parsing and encoding library optimized for high performance and easy usage.

It provides a typeclass-based interface for serializiation and parsing of object hierarchies (see the FromJSON and ToJSON typeclasses) andprovides lazy or strict parsing mechanisms.

Errors can be handled by using Maybe or Either, providing typesafe parsing of any object structure.

In greek mythology, Aeson was the father of Jason, therefore relating the library's name to the format it parses.

383 questions
7
votes
2 answers

Insert default timestamp in fromJson

I have an ajax call sending json to a route in Yesod and I want the route to parse the json and insert it directly into the database. In my model file I have createtime UTCTime default=now() which is preventing parsing the json since the client…
user3776949
  • 237
  • 2
  • 8
7
votes
1 answer

Parsing partial json objects with aeson in haskell

I am making a fairly simple CRUD web service in Haskell with Warp (and possibly Scotty) and acid-state. In acid-state I store User records in a Data.Map (as per this example). I know that those records will always be complete upon creation, so I…
Gurgeh
  • 2,130
  • 15
  • 28
6
votes
1 answer

Haskell, Aeson - no instance for (ToJSON ByteString)

So happy making it this far, encountered a new hurdle: Got this code made to be encoded to JSON. However no matter when type I use as an instance, the compiler complains. Now I am obviously doing something wrong, but it is exactly what is in the…
Madderote
  • 1,107
  • 10
  • 19
6
votes
3 answers

Handling `id` in derived Aeson FromJSON instances with Aeson/JSON

If I have JSON and I try to derive the FromJSON instances automatically with Generics, I run into problems with id existing in more than one place in the JSON. Is there a way for me to override just the id part or do I have to write the whole…
matt
  • 1,817
  • 14
  • 35
6
votes
1 answer

How else but aeson?

aeson seems to take a somewhat simple-minded approach to parsing JSON: it parses a top-level JSON value (an object or array) to its own fixed representation and then offers facilities to help users convert that representation to their own. This…
dfeuer
  • 48,079
  • 5
  • 63
  • 167
6
votes
1 answer

Aeson and Lenses with error handling

I'm very new to the magic of lenses, so I'm having some trouble with this. With reference to: https://www.fpcomplete.com/user/tel/lens-aeson-traversals-prisms a JSON object can be traversed in the following way: val ^? nth 0 . key "someObject" .…
iamnat
  • 4,056
  • 1
  • 23
  • 36
6
votes
2 answers

Serialize a map to YAML with a specific order

I use the yaml library to serialize a value of type Map String t (or some type t). The order in the resulting output is rather random, which is suboptimal, as the file should be human readable. Is there a way to control the serialization order of a…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
6
votes
2 answers

I'd like to store aeson's Value type using acid

I'd like to store aeson Values usig acid-store. I've taken a minimal acid implementation and tried to naively switch the types over to Value. These are my calls to deriveSafeCopy: $(deriveSafeCopy 0 'base ''Object) $(deriveSafeCopy 0 'base…
schellsan
  • 2,164
  • 1
  • 22
  • 32
6
votes
2 answers

How to cope with Haskell name space?

I'm writing a data record to marshall a JIRA JSON object. The problem is, multiple objects have the same labels for name/value pairs. For example : (returned from curl and…
user1198582
5
votes
2 answers

Parsing a nested array of objects with Aeson

I want to parse a JSON object and create a JSONEvent with the given name and args I'm using Aeson, and right now I'm stucked on converting "args":[{"a": "b"}] to a [(String, String)]. Thank's in advance! {-# LANGUAGE OverloadedStrings #-} import…
masylum
  • 22,091
  • 3
  • 20
  • 20
5
votes
1 answer

How can I improve the ease of working with JSON in Haskell?

Haskell has become useful as a web language (thanks Servant!), and yet JSON is still so painful for me so I must be doing something wrong (?) I hear JSON mentioned as a pain point enough, and the responses I've heard revolve around "use PureScript",…
Josh.F
  • 3,666
  • 2
  • 27
  • 37
5
votes
2 answers

Using file name in json parsing (Haskell Aeson)

I have no experience in Haskell. I'm trying to parse many .json files to a data structure in Haskell using aeson. However, by reasons beyond my control, I need to store the name of the file from where the data was parsed as one of the fields in my…
Vitorqb
  • 130
  • 2
  • 6
5
votes
2 answers

In aeson, how do you encode from a Value without resulting in scientific notation?

I have parsed a large amount of json, manipulated some values and I'd like to write it back out. Aeson decodes numbers into scientific, but when it encodes it, by default, scientific shows numbers in scientific notation in many cases, and aeson…
David McHealy
  • 2,471
  • 18
  • 34
5
votes
1 answer

unexpected Haskell Aeson warning: No explicit implementation for 'toJSON"

I am trying to use the aeson library for json parsing and I am following the documentation. This is my code right now: {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} import Data.Aeson as Ae import Data.Text as T import qualified…
TheCrafter
  • 1,909
  • 2
  • 23
  • 44
5
votes
2 answers

How to serialise Haskell ADTs as tidy JSON, using Aeson?

I've spent some time playing around with Aeson, but I can't get Algebraic Data Types to serialise nicely. What I've tried is: data Attach = Attach { tel :: String } deriving (Show) $(deriveJSON defaultOptions ''Attach) data Fix = Fix…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
1 2
3
25 26