aeson

Folding or concatMap-ing an Aeson Array via lenses

天大地大妈咪最大 提交于 2020-08-10 21:22:38
问题 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 construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Folding or concatMap-ing an Aeson Array via lenses

ぐ巨炮叔叔 提交于 2020-08-10 21:19:48
问题 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 construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Folding or concatMap-ing an Aeson Array via lenses

喜夏-厌秋 提交于 2020-08-10 21:19:09
问题 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 construct something of the following type: import Data.Aeson as A functionIWant :: (Vector A.Value) -> (A.Value -> [a]) -> [a] 回答1: There are two lens functions that are used to "lift" regular Foldable -related functions to the lensy world: folded

Decoding object with multiple constuctors with separated tags

▼魔方 西西 提交于 2020-04-16 03:28:19
问题 I have data in form of pairs of two strings, where first is the key identifying shape of the JSON delivered as the second one. fooooo {"a": 123} barrrr {"a": 123, "b": 123} fooooo {"a": 123} I would like to parse it to same data type, based on the fopooo , baasdasda1 , etc : data Test = Foo { a :: Int , b :: Int } | Bar { a :: Int } deriving (Show, Generic) In the Aeson there is a tag feature, but it seems to require presence of the tag inside the object. Is there some way to handle it like

Decoding object with multiple constuctors with separated tags

江枫思渺然 提交于 2020-04-16 03:27:07
问题 I have data in form of pairs of two strings, where first is the key identifying shape of the JSON delivered as the second one. fooooo {"a": 123} barrrr {"a": 123, "b": 123} fooooo {"a": 123} I would like to parse it to same data type, based on the fopooo , baasdasda1 , etc : data Test = Foo { a :: Int , b :: Int } | Bar { a :: Int } deriving (Show, Generic) In the Aeson there is a tag feature, but it seems to require presence of the tag inside the object. Is there some way to handle it like

how to parse json with field of optional and variant type in Haskell?

假装没事ソ 提交于 2020-03-06 09:31:15
问题 How I can parse the input json inside this file ? https://github.com/smogon/pokemon-showdown/blob/master/data/moves.js For the secondary and flags properties? They are optional and contains variant type. A minimal example would be this one: [ {}, { "secondary": false }, { "secondary": { "chance": 10, "boosts": { "spd": -1 } } }, { "secondary": { "chance": 30, "volatileStatus": "flinch" } }, { "secondary": { "chance": 30 } }, { "secondary": { "chance": 10, "self": { "boosts": { "atk": 1, "def"

In aeson-schemas how do you construct an Object of a SchemaType without encoding to text and decoding back?

℡╲_俬逩灬. 提交于 2020-03-03 17:15:41
问题 I'm using aeson-schemas-1.0.3 and I want to construct values of Object Example without round-tripping through an external serialized representation. It seems like a hack and I'm worried about the performance impact. I have this schema defined: type Example = [schema| { example: Text, } |] I want to be able to write something like this: coerceJson $ object [ "example" .= ("Example" :: Text) ] I have a workaround which does allow that, but it involves encoding to a ByteString and decoding to

parsing utctime with aeson

妖精的绣舞 提交于 2020-02-01 16:06:36
问题 I can't get aeson to parse an UTCTime value. I tried to encode one and feed it back, but that didn't work: Prelude Data.Aeson Data.Time.Clock> getCurrentTime >>= (print . encode) "\"2013-10-17T09:42:49.007Z\"" Prelude Data.Aeson Data.Time.Clock> decode "2013-10-17T09:42:49.007Z" :: Maybe UTCTime Nothing Prelude Data.Aeson Data.Time.Clock> decode "\"2013-10-17T09:42:49.007Z\"" :: Maybe UTCTime Nothing The FromJSON instance of the UTCTime type is the following (ref): instance FromJSON UTCTime

parsing utctime with aeson

£可爱£侵袭症+ 提交于 2020-02-01 16:05:22
问题 I can't get aeson to parse an UTCTime value. I tried to encode one and feed it back, but that didn't work: Prelude Data.Aeson Data.Time.Clock> getCurrentTime >>= (print . encode) "\"2013-10-17T09:42:49.007Z\"" Prelude Data.Aeson Data.Time.Clock> decode "2013-10-17T09:42:49.007Z" :: Maybe UTCTime Nothing Prelude Data.Aeson Data.Time.Clock> decode "\"2013-10-17T09:42:49.007Z\"" :: Maybe UTCTime Nothing The FromJSON instance of the UTCTime type is the following (ref): instance FromJSON UTCTime