= camel . drop 1
, omitNothingFields = True
}
toEncoding = genericToEncoding jsonOptions
parseJSON = genericParseJSON jsonOptions
toJSON = Number . fromIntegral . fromVolume
toEncoding = int . fromVolume
parseJSON (Number x) =
let maybeVolume = Scientific.toBoundedInteger x >>= toVolume
in case maybeVolume of
Just vol -> pure vol
Nothing -> fail "Volume number is out of bounds"
parseJSON _ = fail "Volume must be a number"
toEncoding = genericToEncoding jsonOptions
parseJSON = genericParseJSON jsonOptions
toEncoding list =
let (x, xs) = NonEmptyList.uncons list
in toEncoding (x:xs)
parseJSON = withArray "NonEmptyList" $ \array ->
maybe (fail "Unable to parse values") pure (parseValues array)
where
parseVec = sequence . Vector.toList . Vector.map fromJSON
parseValues array = Vector.uncons array >>=
\(head, tail) -> case (fromJSON head, parseVec tail) of
(Success x, Success xs) -> fromList (x:xs)
_ -> fail "Unable to parse values"
toJSON = toJSON . unPrintableText
toEncoding = toEncoding . unPrintableText
parseJSON = withText "PrintableText" $ \text ->
maybe (fail "Text contains only spaces") pure (fromText text)
toJSON value =
let (primer, xs) = value ^. _IndexItem
in object ["primer" .= primer, "locations" .= xs]
toEncoding value =
let (primer, xs) = value ^. _IndexItem
in pairs ("primer" .= primer <> "locations" .= xs)
parseJSON = withObject "IndexItem" $ \value ->
let item = (,) <$> value .: "primer" <*> value .: "locations"
in IndexItem <$> item
parseJSON = withArray "AlBhed.Index" parseValues
where
parseVec = sequence . Vector.toList . Vector.map fromJSON
parseValues array = case parseVec array of
Success x -> pure . IMap.fromList . map (\item@(IndexItem (primer, _)) -> (primer ^. volume & fromVolume, item)) $ x
_ -> fail "Unable to parse values"
toJSON = toJSON . IMap.elems
toEncoding = toEncoding . IMap.elems
decode
eitherDecode
encodeToLazyText
defaultOptions
{ fieldLabelModifier