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

Error on a FromRow instance definition with postgres-simple

data CumulativeRevenue = CumulativeRevenue { payment_date :: T.Text , amount :: Double , sum :: Double } deriving (Show, Generic, Aeson.ToJSON, Aeson.FromJSON) instance Postgres.FromRow CumulativeRevenue where fromRow =…
Sanchayan Maity
  • 637
  • 6
  • 19
0
votes
1 answer

Problem decoding json from input args with Aeson

I'm trying to write a Haskell program that expects Json string provided as input. Expected Json is a list of Person objects. I want to handle a case when user did not provide input by defaulting to Json of empty list. It seems like I'm running into…
marcin_koss
  • 5,763
  • 10
  • 46
  • 65
0
votes
1 answer

Optimize lens based JSON handling

In my current "learning haskell" project I try to fetch weather data from a third party api. I want to extract the name and main.temp value from the following response body: { ... "main": { "temp": 280.32, ... }, ... "name":…
Nicolas Heimann
  • 2,561
  • 16
  • 27
0
votes
1 answer

Parse untagged sum type with aeson

I want to parse external json where RequestItem and FolderItem can show up in the same place. I came with the following encoding where each variant is defined as a separate data type: data RequestItem = RequestItem { name :: String } deriving…
Krever
  • 1,371
  • 1
  • 13
  • 32
0
votes
1 answer

Parsing embedded JSON with Aeson

I'm trying to parse embedded JSON of the form { "foo":"bar", "baz":"\{\"somekey\":\"someval\"\}" } with Aeson in Haskell. Here are my types: data BaseType = BaseType { foo :: String, baz :: EmbeddedType } deriving(Show) instance FromJSON…
thesecretmaster
  • 1,950
  • 1
  • 27
  • 39
0
votes
1 answer

toJson instance single value

I am able to json-encode my data import Data.Aeson (ToJSON, toJSON, (.=), object) import qualified Data.Text as T import qualified Data.Text.Lazy as L data ServiceResponse = ReadServiceResponse L.Text …
Nicolas Heimann
  • 2,561
  • 16
  • 27
0
votes
1 answer

Parse Json Rose Tree with Haskell Aeson

I'm trying to parse recursive JSON data, something like this: { "node": "a", "children": [ { "node": "b", "children": [ { "node": "c", "children": null …
lsund
  • 744
  • 5
  • 16
0
votes
1 answer

Folding or concatMap-ing an Aeson Array via lenses

I've been starting at https://www.stackage.org/haddock/lts-12.1/lens-aeson-1.0.2/Data-Aeson-Lens.html and https://www.stackage.org/haddock/lts-12.1/lens-4.16.1/Control-Lens-Fold.html trying to figure out how to write an expression that allows me to…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
0
votes
0 answers

how to pptable the dynamic json String useing aeson in haskell

I want to use the pptable and the aeson lib to change the json string to table display in console. The json string come from the es table, it just like { "hits": { "hits": [ { "_type": "tableName", "_routing": "key", "_source": { …
savior
  • 802
  • 6
  • 14
0
votes
1 answer

How to extract information from Json file.Json structure must be mapped through type and use AESON

{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} module Main where import Data.Aeson import Data.Aeson.Encode.Pretty import Data.Aeson.Types import Data.ByteString as B import qualified…
Ashot Bes
  • 39
  • 7
0
votes
0 answers

Contextual generation of JSON in Haskell using Aeson

I have a complex nested data structure that I would like to convert to JSON in different ways depending on some provided context. My use case is that my server contains the full state of the world state, but depending on which client is asking for…
Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
0
votes
1 answer

Prelude.read: no parse && Couldn't match expected type ‘Double’ with actual type ‘Text’ In the first argument of ‘WeatherValues’, namely ‘tempMin’

How can I fix it? Couldn't match expected type ‘Double’ with actual type ‘Text’ I can not use text in place of a double.And this is a response Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1,…
Ashot Bes
  • 39
  • 7
0
votes
2 answers

Trouble with JSON (Data.Aeson)

I'm new to Haskell and in order to learn the language I am working on a project that involves dealing with JSON. I am currently getting the feeling Haskell is the wrong language for the job, but that isn't the point here. I've been struggling to…
Orbit
  • 15
  • 3
0
votes
1 answer

Representing Country Id and Text in Haskell datatype

I have a list of country id and country text in json { 1 : "country one", 2 : "country two" } I have created below code to represent country id and text in haskell data Country a = Country a country1 :: Country String -- Representing country…
navin
  • 165
  • 1
  • 12
0
votes
1 answer

Haskell Aeson JSON, filter out illegal characters

Using Haskell with the Aeson JSON Hackage, and given the following JSON: { "base": "GBP", "date": "2017-10-27", "rates": { "#USD": 1.3093, "#EUR": 1.1282 } } What is the beste way to implement a FromJson…
Viletung
  • 137
  • 2
  • 8