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

Expanding Aeson example, how to use array of values?

I am trying to understand a little more Haskell, and have followed an Aeson example with success. I'm trying to adapt it now, and am lacking and what I'm sure is a fairly basic understanding. If it matters, I am doing this in a Jupyter Lab setup…
David Woods
  • 648
  • 7
  • 8
3
votes
1 answer

Construct GADT while parsing json

I have a data structure that I have created with GADT and I want to parse some json to this GADT using aeson. But the type checker complains that It's only possible to create one of the constructors of the GADT in all the cases. See this…
CryptoNoob
  • 469
  • 3
  • 8
3
votes
2 answers

Single tag constructors in Aeson

I have a data type like this: data A = A T.Text deriving (Generic, Show) instance A.ToJSON A If I use A.encode to it: A.encode $ A "foobar" -- "foobar" Then I use singleTagConstructors on it: instance A.ToJSON A where toEncoding a =…
autumn322
  • 447
  • 3
  • 10
3
votes
1 answer

What's mzero in this aeson example?

I saw this question on SO and am trying to replicate it: Haskell: Reusing FromJSON instances with lenses, lens-aeson, and nested JSON However, when I run what I think should be a complete example, I get an error. Here is my code: import…
Elsie Meow
  • 31
  • 2
3
votes
1 answer

Aeson encoding of Data.Map.Strict.Map with custom key type results in array of arrays instead of object

I am having trouble getting Aeson to spit out objects when I use custom types as keys. Let me demonstrate: {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} import Data.Aeson import qualified Data.Map.Strict as M import qualified…
Sergio Losilla
  • 730
  • 1
  • 5
  • 14
3
votes
2 answers

Aeson: derive some (but not all) fields of a struct

I have a large struct which I need to be an instance of FromJSON so that I can parse my json data into it. I would like to derive automatically, but a single field needs "special care" in that it is an object in json and I want it to be an array of…
Marius Melzer
  • 863
  • 1
  • 7
  • 10
3
votes
1 answer

Haskell, Aeson - Is there a better way of parsing historical data?

By 'historical data' I just mean dates as key, and value on that day as value. For example, often govt institutes or uni's research division compile date about earthquakes, rainfalls, market movement, etc. in this format { "Meta Data": { …
user6306428
3
votes
3 answers

How to get HashMap (Object) out of Value in Haskell, Aeson?

I'm trying to get used to some haskell libraries by solving some online practice problems. I have some code which outputs this Object (fromList [("ABC", String "123")]) It may also be Object (fromList [("123", String "ABC")]) Object (fromList…
atis
  • 881
  • 5
  • 22
3
votes
2 answers

Haskell - Aeson : Getting "Nothing" when trying to decode JSON URL Req

I'm relatively new to haskell and right now I'm trying to get a deeper understanding and trying to get used to different popular libraries. Right now I'm trying "aeson". What I want to do is parse MSFT quote request from…
user6306428
3
votes
1 answer

How to update a field of a JSON object?

I'm creating an object as JSON using aeson. How to add a field "email" to the object? > import Data.Aeson > let alice = object ["name" .= "Alice", "age" .= 20] I tried to use <> but didn't work > import Data.Monoid > alice <> object ["email" .=…
Leo Zhang
  • 3,040
  • 3
  • 24
  • 38
3
votes
1 answer

How do I write aeson ToJSON instances for types with kind (* -> *) -> *

Motivation I have a type, MyType, which is parametrised by a functor, f. I want to use MyType Identity to represent "my view" of the data, and MyType Maybe to represent the type of updates to the data. Problem Is it possible to write an aeson ToJSON…
statusfailed
  • 738
  • 4
  • 15
3
votes
1 answer

Haskell Servant Custom JSON parsing errors

Given the following Servant server: {-# LANGUAGE DataKinds #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeOperators #-} module ServantSample (main) where import Data.Aeson import Data.Aeson.TH import Network.Wai import…
adlaika
  • 107
  • 1
  • 8
3
votes
3 answers

Haskell Conduit Aeson: Parsing Large JSONs and filter matching key/values

I have written an application in Haskell that does the following: Recursively list a directory, Parse the JSON files from the directory list, Look for matching key-value pairs, and Return filenames where matches have been found. My first version…
erewok
  • 7,555
  • 3
  • 33
  • 45
3
votes
0 answers

No instance for (MonadHttp m0) arising from a use of ‘req’

I'm a haskell newbie and currently trying to write my first productive haskell program. While I'm using the req package for restful client service like this: test = req GET (http uriString) NoReqBody bsResponse (port 9090) I got the following error…
Theodora
  • 571
  • 4
  • 11
3
votes
1 answer

Use DeriveGeneric for parameterized type

I want to use automated DeriveGeneric for my parameterized type. I get error. I want to decode a yaml file ino FromJSON type. {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeFamilies #-} import Web.Scotty import…
Kamyar
  • 2,494
  • 2
  • 22
  • 33