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
0
votes
1 answer

Haskell Aeson - Gloss - JSON instance parser: Color

We are trying to decode a JSON object using the Aeson-JSON hackage using the following data: data Car = Car { carPosition :: Position, carColor :: Color, carDirection :: Direction } deriving (Show, Generic) Created an instance for…
Viletung
  • 137
  • 2
  • 8
0
votes
1 answer

Parsing JSON into RoseTree (recursive parsing)

I am struggling with a function that would take String JSON as an input and return RoseTree structure as an output. My code is as follows: import qualified Data.Aeson as JSON import qualified Data.Text as T import qualified Data.Aeson.Types as…
altern
  • 5,829
  • 5
  • 44
  • 72
0
votes
1 answer

AESON: Parse dynamic structure

I have a JSON structure like this { "tag1": 1, "tag2": 7, ... } And I have a type like this data TagResult { name :: String, numberOfDevicesTagged :: Int } deriving (Show, Eq) newtype TagResultList = TagResultList { tags :: [TagResult] } The…
Batou99
  • 869
  • 10
  • 19
0
votes
1 answer

Unable to fix "Ambiguous type variable" in Aeson and Spock

I have a Spock application where I have this: post "/test" $ do a <- jsonBody' text "test" It throws an exception: • Ambiguous type variable ‘a0’ arising from a use of ‘jsonBody'’ prevents the constraint ‘(Aeson.FromJSON…
Jodimoro
  • 4,355
  • 3
  • 11
  • 18
0
votes
1 answer

Using a custom datatype in a Aeson record

Preface: I'm still quite a Haskell noob so forgive me if I'm missing something obvious. I'm trying to write aeson ToJSON and FromJSON instances for a record datatype with a field with a non-standard datatype (email address). {-# LANGUAGE DataKinds…
0
votes
1 answer

Haskell read nested timestamp from YAML file

I recently started playing around with Haskell and can't seem to figure this one out. I am trying to read from a YAML file that has this format: id: 1 kind: good created_at: !ruby/object:ActiveSupport::TimeWithZone utc: &1 2017-01-01…
0
votes
0 answers

Use of Aeson pairs results in error "not in scope '<>'"

I am trying to use Aeson to deal with json in haskell, in the documentation it shows the syntax for toEncoding as this: toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age) however, when I try to compile this I get the error: Not…
Marcus Ruddick
  • 9,795
  • 7
  • 28
  • 43
0
votes
1 answer

Exception: JSONError "content type of response is \"application/random.v4+json\"" #Haskell

I am using Network.Wreq, Control.Lens, Data.Aeson getInfo = do let opts = defaults && header "Accept" .~ ["application/random.v4+json"] "Content-Type" .~ ["application/json"] resp <- asJSON =<< getWith opts "url" :: IO (Response (Map String…
Sumanth Kumar Mora
  • 637
  • 1
  • 5
  • 15
0
votes
2 answers

Aeson: FromJSON with nested encoded json

I have JSON that contains an encoded JSON as string in one of its properties: { "firstName": "Frederick", "lastName": "Krueger", "address": "{\"street\": \"Elm Street, 13\", \"city\": \"Springwood\", \"state\": \"OH\"}" } Given that I have a…
Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
0
votes
0 answers

Data structure for Google Places API JSON in Yesod

I am new to Haskell and Yesod development. I try to parse JSON from Google Web Api using Aeson. My JSON is like { "html_attributions" : [], "results" : [ { "geometry" : { "location" : { "lat" :…
DmLitov4
  • 1
  • 1
0
votes
1 answer

Why is Aeson not pattern-matching Text?

I am trying to pattern-match Text to aeson Value using the String constructor, and am running into compile errors. The following example program illustrates the issue I've been running into. {-# LANGUAGE OverloadedStrings #-} import qualified…
mherzl
  • 5,624
  • 6
  • 34
  • 75
0
votes
2 answers

Writing custom instances for JSON date data in Aeson

I have JSON date data in the following form: {"date": "2015-04-12"} and a corresponding haskell type: data Date = Date { year :: Int , month :: Int , day :: Int } How can I write the custom FromJSON and ToJSON functions…
jules
  • 1,897
  • 2
  • 16
  • 19
0
votes
0 answers

Aeson Generics compilation error with manual parseJSON function

I've created my own parseJSON function for my Valuation type. Unfortunately, I get compile errors about there not being a "Generic" version of Valuation and I'm not sure what to make of it. I've read and re-read as many aeson tutorials as I can and…
torrlane
  • 23
  • 1
0
votes
1 answer

How is type inferred in this snippet?

I'm working through Artyom's Aeson tutorial, and have coded myself this snippet: parseFoo (Object obj) = do a <- case HM.lookup "a" obj of Just x -> parseJSON x Nothing -> fail "no field 'a'" return a I've noticed that if…
Ben
  • 54,723
  • 49
  • 178
  • 224
0
votes
1 answer

Haskell Aeson nested array JSON

I have trouble parsing the Tag in the following JSON structure. The parser works only when i declare it to be tags :: !Array It fails when i declare it as tags :: [Tag] Why? { "response": { "status": "ok", "results": [ { …
WellTyped
  • 244
  • 2
  • 10