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

Better ways to collect all unused field of an Object in aeson's Parser?

Suppose I want to implement FromJSON for a data type. Below are the complete source code: {-# LANGUAGE NamedFieldPuns , OverloadedStrings , TupleSections , ViewPatterns #-} module Main ( main ) where import Data.Aeson import…
Javran
  • 3,394
  • 2
  • 23
  • 40
2
votes
1 answer

Unable to collect values from a nested JSON using lenses

Edit I have managed to get my answer after trying several random permutation. But I still don't understand why the former works, but the latter doesn't: x ^.. (key "conversations") . values . (key "id") . _String -- vs x ^@.. (key "conversations")…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
2
votes
1 answer

How to get value from key using Aeson's Parser from very simple Object`

I'm trying to parse some JSON. Given a very simple [Object] how can I get the Value under a string key? Attempt one (guessing): d . key "test" Errors with: • Couldn't match expected type ‘Parser [Object]’ with actual type ‘(Value…
Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
2
votes
1 answer

Correctly Parsing a JSON Array as Custom Data Type Object

I defined the following datatype object in Haskell: import GHC.Generics import Data.Aeson import qualified Data.ByteString.Lazy.Char8 as C import Data.Maybe (fromJust) data DLA = DLA { a::String, b::Int, …
aru_bdd
  • 63
  • 1
  • 6
2
votes
1 answer

Creating an Aeson model from two wreq API calls

I'm looking to solve a problem where I construct some data from a HTTP call and then based off that data I make another HTTP call and enrich the original data with information from the second call. I have code which takes a Spotify Recently Played…
2
votes
0 answers

How to parse something json-like with unquoted keys with aeson?

I am trying to use req library to crawl a page. The response for the page, is almost a JSON object, except for the keys being unquoted. Is it possible to use Aeson to do relaxed parsing of it? What could be the simplest hack that I can do with req…
2
votes
1 answer

Efficient Aeson parsing for sum type toEncoding

I'm parsing a third party JSON structure into my own set of types. I'd like to parse in the most efficient way possible (I'm parsing data sent over a unix socket with Network.Socket) Aeson's documentation claims that parsing with toEncoding yields…
leshow
  • 1,568
  • 2
  • 15
  • 30
2
votes
1 answer

How to use Aeson to get a vector of strings inside a deep JSON object?

Let's say I want to use Aeson to parse the following JSON object: { "data": [ [ "data", "more data" ], [ "data", "more data" ] ], "error": { …
user8370684
2
votes
2 answers

Read single field of object using Aeson without writing a FromJSON instance

How do I read a single field (by name) from a JSON object using Aeson, without writing any type class instance?
Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
2
votes
2 answers

Serialization of a basic sum type in Json with Aeson

type GoalDescription = Text data GoalStatus = Created | Accomplished | InProgress | GivenUp deriving (Show , Eq , Generic ) data Goal = Goal {workspaceId ::WorkspaceId , goalId :: GoalId , description :: GoalDescription , status :: GoalStatus}…
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
2
votes
1 answer

Parsing list with nested list using Aeson

When trying to parse some simple JSON using Aeson I get a type error I don't understand. I have the following JSON jsonString = "[\"a\", [\"b\", \"c\"]]" :: L.ByteString and I have defined the following imports and code: import Data.Aeson import…
Bob Jansen
  • 1,215
  • 2
  • 12
  • 31
2
votes
0 answers

Haskell, Aeson: Parsing nested JSON with part unnecessary values

I'm a beginner trying to learn more about Haskell and Aeson by parsing some json files I find online. I have a .json that looks like this "Abilities": { "Prime": { "Ammo": 210, "Available": true, "Diposition": 3, …
atis
  • 881
  • 5
  • 22
2
votes
1 answer

Haskell, Aeson - Is there a better way of getting the info I need from USDA database?

I'm a Haskell beginner trying to learn JSON parsing by going through USDA database. I want to get the value of "ndbno" key from this link https://api.nal.usda.gov/ndb/search/?format=json&q=potato+salad&sort=n&max=25&offset=0&api_key=DEMO_KEY The…
atis
  • 881
  • 5
  • 22
2
votes
1 answer

Haskell Aeson Parse Mixed Elements Array

I have a json like: { "name" : "Sam", "items": [ "sword", "shield", [] ] } and a data type data Adventurer = Adventurer { name :: String, items :: [String] } deriving (Generic, Show, FromJSON, ToJSON) The problem is caused by the fact that…
oddbit
  • 25
  • 5
2
votes
2 answers

Haskell JSON parsing with Aeson

I have a JSON data source which looks like this: { "fields": [ { "type": "datetime", "name": "Observation Valid", "description": "Observation Valid Time"}, { "type": "datetime", "name": "Observation Valid UTC", "description": "Observation…
guthrie
  • 4,529
  • 4
  • 26
  • 31