Skip to content

JSONPath isn't tracked in autoderived instances #357

Closed
@neongreen

Description

@neongreen

Let's create a type and derive an instance for it.

With TH:

{-# LANGUAGE TemplateHaskell #-}

import Data.Aeson
import Data.Aeson.TH

data X = X {a :: (Int, Int, Int)} 
  deriving Show

deriveJSON defaultOptions ''X

Or with generics:

{-# LANGUAGE DeriveGeneric #-}

import Data.Aeson

data X = X {a :: (Int, Int, Int)}
  deriving (Show, Generic)

instance FromJSON X where
  parseJSON = genericParseJSON defaultOptions 

Then try to decode an invalid value:

> eitherDecode "{\"a\": [1, 2, true]}" :: Either String X
Left "Error in $[2]: expected Int, encountered Boolean"

I believe it should be $.a[2].

(I checked with latest Aeson from the repository, commit 2f0b989.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions