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.

357 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,578
  • 19
  • 63
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
  • 41,289
  • 10
  • 85
  • 162
16
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
  • 898
  • 10
  • 15
15
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
  • 8,297
  • 3
  • 27
  • 54
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
  • 553
  • 6
  • 11
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
  • 502
  • 3
  • 12
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
  • 10,583
  • 7
  • 59
  • 124
12
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,364
  • 8
  • 16
12
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
  • 253
  • 2
  • 10
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
  • 9,481
  • 7
  • 35
  • 53
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,045
  • 5
  • 34
  • 41
12
votes
1 answer

Fault tolerant JSON parsing

I'm using Data.Aeson to parse some JSON into a Record type. From time to time data is added to the JSON and this breaks my code as Aeson complains something to the effect of: expected Object with 21 name/value pairs but got 23 name/value I'd…
hackerhasid
  • 11,151
  • 9
  • 40
  • 60
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
  • 12
11
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
  • 24,322
  • 4
  • 41
  • 79
10
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
  • 440
  • 4
  • 10
1
2 3
23 24