pdToValue :: D.PackageDescription -> UTCTime -> Maybe [T.Text] -> JSON.Value
pdToValue p upl dpr = JSON.object
    [ "name"          .= name
    , "version"       .= (D.display . D.pkgVersion . D.package) p
    , "license"       .= (D.display . D.license) p
    , "copyright"     .= D.copyright p
    , "maintainer"    .= D.maintainer p
    , "author"        .= D.author p
    , "stability"     .= D.stability p
    , "homepage"      .= D.homepage p
    , "bugReports"    .= D.bugReports p
    , "synopsis"      .= D.synopsis p
    , "description"   .= (unescapeHtml . D.description) p
    , "category"      .= (splitCategory . D.category) p
    , "hasLibrary"    .= (isJust . D.library) p
    , "hasExecutable" .= (not . null . D.executables) p
    , "executables"   .= (map D.exeName . D.executables) p
    , "deprecated"    .= isJust dpr
    , "inFavourOf"    .= maybe [] id dpr
    , "lastUploaded"  .= upl
    , "ngram"         .= JSON.object
        [ "description" JSON..= (unescapeHtml . D.description) p
        , "synopsis"    JSON..= (unescapeHtml . D.synopsis) p
        , "name"        JSON..= name
        ]
    , "raw"           .= JSON.object
        [ "name"     .= name
        , "license"  .= (D.display . D.license) p
        , "category" .= (splitCategory . D.category) p
        ]
    ]
  where
    splitCategory = map T.strip . T.splitOn "," . T.pack
    name = (D.display . D.pkgName    . D.package) p
pdToValue :: D.PackageDescription -> UTCTime -> Maybe [T.Text] -> JSON.Value
pdToValue p upl dpr = JSON.object
    [ "name"          .= name
    , "version"       .= (D.display . D.pkgVersion . D.package) p
    , "license"       .= (D.display . D.license) p
    , "copyright"     .= D.copyright p
    , "maintainer"    .= D.maintainer p
    , "author"        .= D.author p
    , "stability"     .= D.stability p
    , "homepage"      .= D.homepage p
    , "bugReports"    .= D.bugReports p
    , "synopsis"      .= D.synopsis p
    , "description"   .= (unescapeHtml . D.description) p
    , "category"      .= (splitCategory . D.category) p
    , "hasLibrary"    .= (isJust . D.library) p
    , "hasExecutable" .= (not . null . D.executables) p
    , "executables"   .= (map D.exeName . D.executables) p
    , "deprecated"    .= isJust dpr
    , "inFavourOf"    .= maybe [] id dpr
    , "lastUploaded"  .= upl
    , "ngram"         .= JSON.object
        [ "description" JSON..= (unescapeHtml . D.description) p
        , "synopsis"    JSON..= (unescapeHtml . D.synopsis) p
        , "name"        JSON..= name
        ]
    , "raw"           .= JSON.object
        [ "name"     .= name
        , "license"  .= (D.display . D.license) p
        , "category" .= (splitCategory . D.category) p
        ]
    ]
  where
    splitCategory = map T.strip . T.splitOn "," . T.pack
    name = (D.display . D.pkgName    . D.package) p
pdToValue p upl dpr = JSON.object
    [ "name"          .= name
    , "version"       .= (D.display . D.pkgVersion . D.package) p
    , "license"       .= (D.display . D.license) p
    , "copyright"     .= D.copyright p
    , "maintainer"    .= D.maintainer p
    , "author"        .= D.author p
    , "stability"     .= D.stability p
    , "homepage"      .= D.homepage p
    , "bugReports"    .= D.bugReports p
    , "synopsis"      .= D.synopsis p
    , "description"   .= (unescapeHtml . D.description) p
    , "category"      .= (splitCategory . D.category) p
    , "hasLibrary"    .= (isJust . D.library) p
    , "hasExecutable" .= (not . null . D.executables) p
    , "executables"   .= (map D.exeName . D.executables) p
    , "deprecated"    .= isJust dpr
    , "inFavourOf"    .= maybe [] id dpr
    , "lastUploaded"  .= upl
    , "ngram"         .= JSON.object
        [ "description" JSON..= (unescapeHtml . D.description) p
        , "synopsis"    JSON..= (unescapeHtml . D.synopsis) p
        , "name"        JSON..= name
        ]
    , "raw"           .= JSON.object
        [ "name"     .= name
        , "license"  .= (D.display . D.license) p
        , "category" .= (splitCategory . D.category) p
        ]
    ]
  where
    splitCategory = map T.strip . T.splitOn "," . T.pack
    name = (D.display . D.pkgName    . D.package) p