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

Convert array of tuples to JSON in Haskell

Would ayone know how to convert tt :: (Int, [(Int, String)]) tt = (777, [(1, "AA") , (2, "BB") , (3, "CC")]) to JSON similar to { "user": 777, "data": [ { "num": 1 , "typ": "AA" }, { "num": 2 , "typ": "BB" }, {…
Damir Sudarevic
  • 21,891
  • 3
  • 47
  • 71
3
votes
2 answers

Parsing/exporting arbitrarily nested JSON objects to maps in Haskell

I need to be able to parse a giant nested JSON structure into something more malleable, preferably a map from strings to strings. Example of the kinds of structures I'm talking about: { "foo" : "baz", "bar" : {"qux" : "quux", "baz" : {"abracadabra"…
gallabytes
  • 267
  • 1
  • 9
3
votes
1 answer

Trouble using Aeson to decode string

I am attempting to use aeson to parse the json returned by an api. A response is fetched from the api endpoint using wreq. When running eitherDecode on this string I get: Left "Failed reading: Cannot decode byte '\\xa3':…
oneway
  • 753
  • 1
  • 5
  • 9
3
votes
2 answers

Transforming a Haskell JSON Lens expression back to JSON

How can I suffix the following Aeson Lens expression >>> "{\"a\": 4, \"b\": 7}" & members . _Number *~ 10 "{\"a\":40,\"b\":70}" so that the result is a Value (with an Object constructor) and not a String?
z1naOK9nu8iY5A
  • 903
  • 7
  • 22
3
votes
1 answer

How to deliver JSON over HTTP using Warp with Aeson

I want to create a high-performance HTTP-based API running on Haskell using warp as a HTTP backend. The server shall return JSON data upon request. This data shall be serialized by using Aeson However, warp requires a response object whereas Aeson…
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
3
votes
2 answers

Haskell Aeson JSON Library ByteString Issue

I'm having trouble finding a function or workaround to convert a String to Data.ByteString.Lazy.Internal.ByteString One of the functions in the Aeson Json library is decode and has the following description: decode :: FromJSON a =>…
MathanMV
  • 412
  • 1
  • 5
  • 16
3
votes
1 answer

Why Aeson encodes () as empty array?

I am surprised to know that Aeson encodes () as empty array. What is reason behind such behaviour? I think null would be more natural, am I wrong? *Main> encode () "[]"
lambdas
  • 3,990
  • 2
  • 29
  • 54
3
votes
1 answer

Why would this code produce a segfault?

I am trying to write a module that parses xml from an api, strips out some information, and prints the result as json, but I've hit a hiccup at the printing step. If I print shows I do indeed see that the correct data is there, however, the call…
Javon Harper
  • 176
  • 7
2
votes
3 answers

How to do mapMaybe using lenses

I am using wreq on the github api to get a list of files in a repository. I include this for completeness sake. This isn't about doing the web request: let myOpts = defaults & header "Accept" .~ ["application/vnd.github.raw"] …
ruben.moor
  • 1,876
  • 15
  • 27
2
votes
1 answer

Baffling error trying to decode with Aeson

I've been beating my head against the wall for a while on an Aeson decoding problem. Briefly, when used in the context of the app as in line (6) below, the decoder fails, giving the error src/CFUpload.hs:(66,6)-(71,27): Non-exhaustive patterns in…
jxxcarlson
  • 223
  • 3
  • 13
2
votes
1 answer

Aeson merge object encodings

I want to parse and write JSON objects that have some base attributes in common and some additional individual attributes. For example, let's say we have two types of objects User and Email. Both types share the same base attributes foo and bar, but…
Lando-L
  • 843
  • 6
  • 19
2
votes
2 answers

Parse JSON with known variable field

I have a Haskell query function to get latest token price using https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyQuotesLatest The function takes token id as arg, say 2010 for ADA. import Data.Aeson import…
Kwaggy
  • 137
  • 4
2
votes
1 answer

Overlapping instances for aeson

After installing new version of aeson (ghc-pkg list | grep aeson shows aeson-1.4.7.1) I now have a following error: RoseTree.hs:17:69: error: • Overlapping instances for aeson-1.2.1.0:Data.Aeson.Types.ToJSON.RecordToPairs …
altern
  • 5,829
  • 5
  • 44
  • 72
2
votes
1 answer

Haskell & JSON - dealing with null

I'm fairly new to Haskell and have been using Wreq to interact with a JSON API. I'm having an issue trying to edit a JSON response before submitting it back to the API. I think the problem lies with an undefined Bool. In short, the Wreq response…
Al_M
  • 63
  • 6
2
votes
2 answers

Is it possible to match a changing JSON key to a sum type data constructor with aeson inside a larger record type?

So I have this data type ItemType which is decoded using its data constructor name (see the FromJSON instance). import Data.Aeson import Data.Aeson.Types import Data.Char (toLower) import GHC.Generics data…
skykanin
  • 23
  • 3