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
25
votes
3 answers

Why doesn't GHC Haskell support overloaded record parameter names?

What I am talking about is that it is not possible to define: data A = A {name :: String} data B = B {name :: String} I know that the GHC just desugars this to plain functions and the idiomatic way to solve this would be: data A = A {aName ::…
fho
  • 6,787
  • 26
  • 71
20
votes
1 answer

Why do library designers use ByteString where Text seems to be appropriate?

Working on my app I've stumbled into a problem of Aeson not decoding UTF8 input. Digging deeper I found out that it relies on Parser ByteString of Attoparsec, which seems to be the source of the problem to me. But it's actually not what I'm asking…
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
17
votes
2 answers

How to trace back parsing errors with Aeson? [+Answer]

I have big (>1Mb), simple JSON files to parse. I used Aeson, following the tutorial of fpcomplete in their School of Haskell (thank you guys, btw). As some files (and not all) fail, I suspect the json file not to respect the structure that I am…
Titou
  • 968
  • 10
  • 16
16
votes
2 answers

What is difference between decode and decode' functions from aeson package?

Functions decode and decode' from aeson package are almost identical. But they have subtle difference described in documentation (posting only interesting part of docs here): -- This function parses immediately, but defers conversion. See -- 'json'…
Shersh
  • 9,019
  • 3
  • 33
  • 61
13
votes
3 answers

Haskell, Aeson & JSON parsing into custom type

Following on from a previous post, I've found I'm totally stuck. I'm trying to parse a JSON structure into my own type, and not only am I stuck on how to parse the Array, I'm not even sure if I'm using the Aeson library as intended. Any help would…
Snoqual
  • 573
  • 6
  • 11
13
votes
2 answers

Using lens to add key and value to a nested Map

I am struggling to figure out an issue with manipulating JSON with Aeson lenses. My task is as simple as to add a key to a nested object in JSON. I was able to change the existing keyby means of: > :set -XOverloadedStrings > import Control.Lens >…
SkyWriter
  • 1,454
  • 10
  • 17
13
votes
1 answer

Is it possible to list the names and types of fields in a record data type that derives Generic?

I know that for data types that derive Data.Data, constrFields gives the list of field names. Looking at the GHC.Generics documentation, I think the same should be possible for Generic as well. (but miserably failed to figure out how to do it…
Minoru
  • 512
  • 3
  • 12
13
votes
2 answers

Parsing Nested JSON in Haskell with Aeson

I'm trying to parse JSON from a RESTful API. The returned JSON is highly nested and may/may not include certain fields. Here is an example of some returned data: { resultSet : { location : [{ desc : "Tuality Hospital/SE…
Blake Clough
  • 263
  • 2
  • 10
13
votes
1 answer

Couldn't match expected type 'Data.ByteString.Lazy.Internal.ByteString' with actual type '[Char]'

I'm trying to get a simple Json parser up and running in my Haskell code, I came across Data.Aeson which seemed like a viable solution to my problem I followed the example code on the page, and with some minor modifications, here's what I…
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
12
votes
1 answer

parsing utctime with aeson

I can't get aeson to parse an UTCTime value. I tried to encode one and feed it back, but that didn't work: Prelude Data.Aeson Data.Time.Clock> getCurrentTime >>= (print . encode) "\"2013-10-17T09:42:49.007Z\"" Prelude Data.Aeson Data.Time.Clock>…
Simon Bergot
  • 10,378
  • 7
  • 39
  • 55
12
votes
1 answer

How to avoid creating an orphan FromJSON instance for Data.Tree

I'm using the aeson package. I have a datatype which uses Data.Tree in its declaration. Like the following, only more complex: data Foo = Foo { bat :: Text , xux :: Maybe Text , tri :: Tree Text …
danidiaz
  • 26,936
  • 4
  • 45
  • 95
12
votes
1 answer

Arbitrary JSON keys with Aeson - Haskell

I have a bunch of nested JSON objects with arbitrary keys. { "A": { "B": { "C": "hello" } } } Where A, B, C are unknown ahead of time. Each of those three could also have siblings. I'm wondering if there is a…
Honza Pokorny
  • 3,205
  • 5
  • 37
  • 43
11
votes
2 answers

How to deal with Haskell's reserved keywords in record fields?

JSON in response of Github Gists Rest API contains Haskell's keyword type. But type couldn't be used as a record field. Thus it couldn't be used in implementation of Aeson's Generic FromJSON/ToJSON instances. import Data.Text (Text) import…
palik
  • 2,425
  • 23
  • 31
11
votes
2 answers

Haskell :: Aeson :: parse ADT based on field value

I'm using an external API which returns JSON responses. One of the responses is an array of objects and these objects are identified by the field value inside them. I'm having some trouble understanding how the parsing of such JSON response could be…
ksaveljev
  • 550
  • 2
  • 16
11
votes
2 answers

How to parse an array with Haskell Aeson

I have a JSON doc that looks like: { "series": [[1,2], [2,3], [3,4]] } I'd like to parse this into a set of data types: data Series = Series [DataPoint] data DataPoint = DataPoint Int Int -- x and y I'm having lots of problems trying to write the…
cschneid
  • 460
  • 4
  • 10
1
2 3
25 26