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

Query properties of Object

What's the Aeson equivalent of the javascript property accessor. How would you translate the javascript statement x.a.b to Haskell? As an example, given someObject :: Object containing e.g: { a: { b: [ 1 , 2 ] } } What would the…
fredefox
  • 681
  • 3
  • 11
0
votes
2 answers

Haskell Aeson JSON Object inside JSON Array

I am trying to convert a JSON String into an ADT This is my ADT: data UserList = UserList { userListUsers :: [UserId] } This is my FromJSON instance for UserList: instance FromJSON UserList where parseJSON (Object o) = UserList <$> ((o .:…
FtheBuilder
  • 1,410
  • 12
  • 19
0
votes
1 answer

Is there a clean way to retain information while unwrapping a JSON object with Aeson?

I’m attempting to parse a JSON object which is described by the following “model schema”: { "(archived|active)_org": { "id": "", "description": "", "reference": "", "bucket_name": "", "version": 0 } } (Taken directly from…
Jason Whittle
  • 751
  • 4
  • 23
0
votes
1 answer

How to parse a list of Json objects in Haskell?

I have a data class: data MyData = MyData { a :: Int, b :: String } instance ToJSON MyData where .... instance FromJSON MyData where .... I can parse a single object from json: get :: IO (Maybe MyData) get = do res <- getSingleItemHttp …
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
0
votes
0 answers

Efficiently add trailing newline to JSON ByteString emitted by Aeson when writing to file

By default, Aeson encode or encodePretty do not append a trailing newline to the ByteString. I.e., when viewing the resulting file in vim I see the [noeol] indicator. What is a performant/idiomatic way to append a newline to the file? Here's an…
kostmo
  • 6,222
  • 4
  • 40
  • 51
0
votes
1 answer

Type Variables in Instance Decelerations (Aeson)

I have JSON data that may either look like this { "items": [Day], "pageCount": Int, "totalCount": Int } or this { "items": [Order], "pageCount": Int, "totalCount": Int } I've been trying to create a data type for the unvaried fields for use with…
0
votes
0 answers

Having trouble generating arbitrary json with Haskell's Aeson package

I'm a Haskell newb, having only just finished reading LYAH. I am reading this Aeson tutorial, but I'm having trouble executing most of the code examples. For instance, I have the following in Scratch01.hs ... {-# LANGUAGE OverloadedStrings…
Jonny Appleseed
  • 121
  • 1
  • 8
0
votes
1 answer

Unsure how to assign monadic value to Aeson pair

Consider the following code: S.get "/budget/:bid/month/:mnth" $ do mbid <- param "bid" (budget :: Maybe Budget) <- liftIO $ getBudget $ toSqlKey mbid (categories :: [Entity Category]) <- liftIO $ getCategories $ toSqlKey mbid …
acrognale
  • 170
  • 1
  • 2
  • 8
0
votes
1 answer

Parse top-level value with Aeson

I'm trying to parse JSON values with Aeson and I have no problem (so far) parsing objects or arrays, but I can't get Aeson to parse JSON documents that are just strings. As I understand, since RFC 7159 values are legal JSON documents, and Aeson…
klozovin
  • 2,363
  • 2
  • 22
  • 30
0
votes
1 answer

How to parses nested JSON, which also contains lists,in Haskell?

I am trying to parse the fallowing JSON with aseon: JSON { "response": [ { "id": 5555, "brandId": 10, "productTypeId": 1, "identity": { "sku": "ABCDEF", "ean": "1111", "barcode": "2222" }, …
matt
  • 1,817
  • 14
  • 35
0
votes
2 answers

Parsing "the rest" of an aeson object

for some reason I can't wrap my head around arbitrarilly successful parses in Aeson, without making the whole system bork and cause a space leak. Here's my issue: newtype Foo = Foo { getFoo :: [(String, Maybe String)] } deriving (Show,…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
0
votes
1 answer

Serializing values to JSON array with pipes

I'd like to serialize incoming values to JSON. Every value has a toJSON instance. The end result should be a list. The current code is the following: import Pipes import qualified Pipes.Prelude as P -- assume a source of elements main :: IO () main…
rubik
  • 8,814
  • 9
  • 58
  • 88
0
votes
0 answers

how to access a element from JSON and create a new list with this element in haskell

I have this data structure to take the result from a JSON in Haskell, with aeson From this URL: http://fipeapi.appspot.com/api/1/carros/marcas.json data Marca = Marca { keyM :: String , idM :: Int , fipe_nameM ::…
0
votes
2 answers

is it possible to parse and consume the results of an aeson parser from a stream in constant space?

Note that fromJson returns a Result a, which can be an Error String or Success a. If I'm using fromJson on a stream (for example, a response from http-streams using the expression parseFromStream (fromJSON <$> json') ) (link), does pattern…
9b5b
  • 1,508
  • 11
  • 20
0
votes
1 answer

Is there an AsValue instance for nested Vectors of Aeson Values?

I'm trying to get the feel of aeson package. Am I using its Lens API incorrectly? > :t bt ^? _Array bt ^? _Array :: Maybe (vector-0.10.12.2:Data.Vector.Vector Value) > :t bt ^? _Array . nth 0 . _Array :1:16: No instance for…
sevo
  • 4,559
  • 1
  • 15
  • 31
1 2 3
25
26