How can I convert JSON to Value or Data(Haskell) with Data.Aeson or get AST with arbitrary JSON if I don't know beforehand the structure of JSON?
Asked
Active
Viewed 137 times
1 Answers
4
The decode
function does this.
decode :: FromJSON a => ByteString -> Maybe a
Here are some examples, taken directly from the Data.Aeson
module documentation:
>>> decode "{\"foo\": 123}" :: Maybe Value
Just (Object (fromList [("foo",Number 123)]))
>>> decode "{\"foo\": [\"abc\",\"def\"]}" :: Maybe Value
Just (Object (fromList [("foo",Array (fromList [String "abc",String "def"]))]))

Chris Martin
- 30,334
- 10
- 78
- 137