I'm learning Argonaut and I'm able to decode json manually:
foo = """{"f":"xxx"}"""
newtype Foo =
Foo {
f :: String
}
derive instance genericFoo :: Generic Foo
instance decodeJsonFoo :: DecodeJson Foo where
decodeJson json = do
obj <- decodeJson json
f <- obj .? "f"
pure $ Foo { f }
main = either log (\x -> log $ show $ decodeJson x :: Either String Foo) (jsonParser foo)
I'm trying to use Generics instead and I thought
instance decodeJsonFoo :: DecodeJson Foo where
decodeJson = gDecodeJson
would work.
however, I got (Left "When decoding a Main.Foo: 'tag' property is missing")
looked at Generic.purs but I'm new to Generics and can't figure out.
Do I misunderstand something or how can I fix this?