Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell Aeson JSON Library ByteString Issue
    primarykey
    data
    text
    <p>I'm having trouble finding a function or workaround to convert a <strong>String</strong> to <code>Data.ByteString.Lazy.Internal.ByteString</code></p> <p>One of the functions in the Aeson Json library is <code>decode</code> and has the following description: </p> <pre><code>decode :: FromJSON a =&gt; bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString -&gt; Maybe a </code></pre> <p>I've tried using the pack function in Data.ByteString.Lazy.Char8 but that returns a different ByteString. Any one know how this can be fixed?</p> <p>The following is the example I'm working on:</p> <pre><code>import Data.Aeson import Data.Text import Control.Applicative import Control.Monad (mzero) import qualified Data.ByteString.Lazy.Internal as BLI import qualified Data.ByteString.Lazy.Char8 as BSL data Person = Person { name :: Text , age :: Int } deriving Show instance FromJSON Person where parseJSON (Object v) = Person &lt;$&gt; v .: (pack "name") &lt;*&gt; v .: (pack "age") parseJSON _ = mzero </code></pre> <p>I tried using <code>decode (BSL.pack "{\"name\":\"Joe\",\"age\":12}") :: Maybe Person</code> and got the following error message:</p> <pre><code>Couldn't match expected type `bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString' with actual type `BSL.ByteString' In the return type of a call of `BSL.pack' In the first argument of `decode', namely `(BSL.pack "{\"name\":\"Joe\",\"age\":12}")' In the expression: decode (BSL.pack "{\"name\":\"Joe\",\"age\":12}") :: Maybe Person </code></pre> <p>Help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload