Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Aeson: parsing json with 'data' field (Derek McLoughlin)
   2. Re:  Aeson: parsing json with 'data' field (Miro Karpis)
   3. Re:  Connecting telnet connection to a wx widget
      (Henk-Jan van Tuyl)


----------------------------------------------------------------------

Message: 1
Date: Sat, 4 Oct 2014 17:40:59 +0100
From: Derek McLoughlin <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Subject: Re: [Haskell-beginners] Aeson: parsing json with 'data' field
Message-ID:
        <CAAw9fmnKsupM0a=FNNKpA2UR=DYKme540=qrmjzpedcym8o...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

{-# LANGUAGE OverloadedStrings #-}

import Data.Aeson ((.:), (.:?), decode, FromJSON(..), Value(..))
import Control.Applicative ((<$>), (<*>))
import qualified Data.ByteString.Lazy.Char8 as BS

data Foo = Foo {
              _data :: String -- call it anything you like
           }
           deriving (Show)

instance FromJSON Foo where
  parseJSON (Object v) =
    Foo <$>
    (v .: "data")

Testing:

ghci> let json = BS.pack "{\"data\":\"hello\"}"
ghci> let (Just x) = decode json :: Maybe Foo|
ghci> x
Foo {_data = "hello"}



On 4 October 2014 08:07, Miro Karpis <[email protected]> wrote:
> Hi,
> please can you help me with this.......I have a json file which contains a
> field with name "data". Problem is that I can not create a data type with
> "data", (or can I)? How else can I handle this? I know I can convert all
> json to Object and then search for the field....but I was hoping for some
> friendly/easier option.
>
>
> json example:
>
> {
>   "data" : {
>     "foo" : "bar"
>   }
> }
>
>
> below definition returns: parse error on input ?data?
> data Foo = Foo {
>   data :: String
> }
>
>
> Cheers,
> Miro
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


------------------------------

Message: 2
Date: Sat, 4 Oct 2014 21:23:46 +0200
From: Miro Karpis <[email protected]>
To: Derek McLoughlin <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Aeson: parsing json with 'data' field
Message-ID:
        <cajnnbxhj7t2wsuvtzjeq+hj3xpnfaltyxa6odb1+dxkt4u9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

thank you, that helped ;-)

On Sat, Oct 4, 2014 at 6:40 PM, Derek McLoughlin <[email protected]
> wrote:

> {-# LANGUAGE OverloadedStrings #-}
>
> import Data.Aeson ((.:), (.:?), decode, FromJSON(..), Value(..))
> import Control.Applicative ((<$>), (<*>))
> import qualified Data.ByteString.Lazy.Char8 as BS
>
> data Foo = Foo {
>               _data :: String -- call it anything you like
>            }
>            deriving (Show)
>
> instance FromJSON Foo where
>   parseJSON (Object v) =
>     Foo <$>
>     (v .: "data")
>
> Testing:
>
> ghci> let json = BS.pack "{\"data\":\"hello\"}"
> ghci> let (Just x) = decode json :: Maybe Foo|
> ghci> x
> Foo {_data = "hello"}
>
>
>
> On 4 October 2014 08:07, Miro Karpis <[email protected]> wrote:
> > Hi,
> > please can you help me with this.......I have a json file which contains
> a
> > field with name "data". Problem is that I can not create a data type with
> > "data", (or can I)? How else can I handle this? I know I can convert all
> > json to Object and then search for the field....but I was hoping for some
> > friendly/easier option.
> >
> >
> > json example:
> >
> > {
> >   "data" : {
> >     "foo" : "bar"
> >   }
> > }
> >
> >
> > below definition returns: parse error on input ?data?
> > data Foo = Foo {
> >   data :: String
> > }
> >
> >
> > Cheers,
> > Miro
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141004/4a347669/attachment-0001.html>

------------------------------

Message: 3
Date: Sun, 05 Oct 2014 00:41:44 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
To: [email protected], Tilmann <[email protected]>
Subject: Re: [Haskell-beginners] Connecting telnet connection to a wx
        widget
Message-ID: <op.xm79by0wpz0j5l@alquantor>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes

On Wed, 01 Oct 2014 12:37:36 +0200, Tilmann <[email protected]> wrote:

> Hi,
>
> I am stuck at this problem. I want to read from a telnet connection and  
> display the result in a wxHaskell widget (textCtrl). I got the widget  
> and I got the connection piped to stdout, but I don?t know how to  
> connect the two. Any help is greatly appreciated!
:
:

As you haven't got an answer yet, it looks like there is no one with both  
wxHaskell and Conduit knowledge on this mailing list; I suggest to try the  
Haskell Caf? mailing list.

Regards,
Henk-Jan van Tuyl


-- 
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/


http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 76, Issue 5
****************************************

Reply via email to