Re: [elm-discuss] Parsing JSON — one more victim

2016-07-27 Thread Eduardo Cuducos
@Rex: I join this chant: nice trick this one on debugging — once more,
thanks, Peter! (and, yes, this community os awesome!)

@Peter: I've seem things that belong to the “public/common” such as a
decentralized Twitter
 or Chicago
transit timetable ! Maybe they are
not civic activism, but the decentralized Twitter is *per se* a political
and civic claim in itself IMHO… Anyway, this tiny page I created has
started with React managing the DOM in a smart way; thus I had the idea to
replace React by Elm in baby-steps. A couple of weeks ago I got rid of
react. Today I just completed the full migration of the HTML body to Elm <3

On Wed, Jul 27, 2016 at 6:33 PM Rex van der Spuy 
wrote:

>
>
> On Tuesday, July 26, 2016 at 7:27:25 AM UTC-4, Eduardo Cuducos wrote:
>>
>> You could be very mean due to my typo.
>>
>
> This is the Elm Community, we don't do mean here :)
>
> I had a similar, infuriating JSON decoding bug due to a simple typo that
> took me hours to find ... argh! :)
>
> Peter, I didn't know that trick about debugging the decoder, thanks for
> explaining it.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Parsing JSON — one more victim

2016-07-27 Thread Rex van der Spuy


On Tuesday, July 26, 2016 at 7:27:25 AM UTC-4, Eduardo Cuducos wrote:
>
> You could be very mean due to my typo. 
>

This is the Elm Community, we don't do mean here :)

I had a similar, infuriating JSON decoding bug due to a simple typo that 
took me hours to find ... argh! :)

Peter, I didn't know that trick about debugging the decoder, thanks for 
explaining it.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Parsing JSON — one more victim

2016-07-26 Thread Eduardo Cuducos
Yay, deployed: https://github.com/cuducos/cunhajacaiu

It's a tiny project that I use to test my Elm skills and, surely, to learn
Elm.

Nothing very complex, Elm is updating the stopwatch, and loading the news —
loading both initial data from different JSON API (but once loaded, no
interaction is done but the “tick” from the stopwatch).

Except exercises and tutorials, this is my very first Elm project, so
probably there is a lot to improve (suggestions, comments, critiques, etc
are more than welcome).

The Elm modules are in cunhajacaiu/static/elm


Many thanks for all the help, guys,


Eduardo Cuducos
http://cuducos.me/

On Tue, Jul 26, 2016 at 1:47 PM, Peter Damoc  wrote:

> To paraphrase Satchmo, "If lots more of us helped each other, we’d solve
> lots more problems. And then this world would be better."
> I'm glad I could help. ;)
>
>
> On Tue, Jul 26, 2016 at 2:27 PM, Eduardo Cuducos 
> wrote:
>
>> Peter, thank you so much.
>>
>> You could be very mean due to my typo. Still you helped me a lot
>> combining Json.Decode.decodeString and Debug.log something I would take
>> ages to figure out.
>>
>> I could get it to work with local (sample) and real data now! I'll update
>> this topic once the code is up on GitHub ; )
>>
>> Thank you very much.
>>
>> On Tue, Jul 26, 2016 at 12:48 PM Peter Damoc  wrote:
>>
>>> OK,
>>>
>>> So, first, you had a typo in the decoder. it says "chidren" instead
>>> of "children"
>>>
>>> This is why it is better to first debug the decoder with fake but valid
>>> data and then move to retrieve the data from a live source.
>>>
>>> You do this by just prettifying the json and pasting it into a triple
>>> quote string value.
>>> And then you use Json.Decode.decodeString with this string value and
>>> inspect the result using Debug.log
>>>
>>> Here is how I modified your model to inspect:
>>>
>>>
>>> decodeJson =
>>> let
>>> data =
>>> Debug.log "" (Json.decodeString decodeNews json_data)
>>> in
>>> Result.withDefault [] data
>>>
>>>
>>> model : Model
>>> model =
>>> { news = decodeJson }
>>>
>>>
>>> I've used only the first two items from the json because it seams to
>>> trigger another error.
>>> I don't have time to investigate further but it seams that the Json
>>> library considers the JSON invalid and it looks like it's happening around
>>> stuff like this:
>>>
>>> "content":"iframe class="embedly-embed"
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Jul 26, 2016 at 12:33 PM, Eduardo Cuducos 
>>> wrote:
>>>
 Ow, sorry — thanks for letting me know, Peter.
 Here are the correct links:

- Original JSON: https://www.reddit.com/search.json?q=subreddit:elm
- My code so far:
https://gist.github.com/cuducos/479ff955e3a8e18616f1905ae0a38774

 Peter, if I create a small JSON should I put it in a (local) HTTP or
 Json.Decoder loads from the file system?

 Many thanks,

 On Tue, Jul 26, 2016 at 10:47 AM Peter Damoc  wrote:

> The links you tried to post are broken.
>
> Have you tried creating a small sample JSON to test your decoders on?
>
>
>
> On Tue, Jul 26, 2016 at 11:17 AM, Eduardo Cuducos 
> wrote:
>
>> Hi all,
>>
>> I'm tryind to parse Reddit JSON
>> <#m_5531829199268513028_m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>  but I think I'm failing at the Json.Decoder— however I'm not sure
>> if that really is the problem, and I don't know what else to try.
>>
>> The (ugly) JSON has this format (not so ugly after cleaned up, BTW):
>>
>> {
>>   "data": {
>> "children": [
>>   {
>> "data": {
>>   "title": "Post title",
>>   "url": "http://po.st/url;,
>>   "domain": "po.st",
>>   …
>> },
>> …
>>   },
>>   …
>> ],
>> …
>>   }
>>   …}
>>
>> I want to parse the title, url and domain inside
>> data.children[i].data (where i stands for each element of the
>> list/array) in news list from my Elm model:
>>
>> type alias NewsItem =
>> { title : String
>> , url : String
>> , domain : String
>> }
>> type alias Model =
>> { news : List NewsItem }
>>
>> I've tried this without success:
>>
>> decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
>> Json.object3 NewsItem
>> (Json.at ["data", "title"] Json.string)
>> (Json.at ["data", "url"] Json.string)
>> (Json.at ["data", "domain"] Json.string)
>> decodeNews : Json.Decoder (List NewsItem)decodeNews =
>> Json.at ["data", "chidren"] 

Re: [elm-discuss] Parsing JSON — one more victim

2016-07-26 Thread Peter Damoc
To paraphrase Satchmo, "If lots more of us helped each other, we’d solve
lots more problems. And then this world would be better."
I'm glad I could help. ;)


On Tue, Jul 26, 2016 at 2:27 PM, Eduardo Cuducos  wrote:

> Peter, thank you so much.
>
> You could be very mean due to my typo. Still you helped me a lot combining
> Json.Decode.decodeString and Debug.log something I would take ages to
> figure out.
>
> I could get it to work with local (sample) and real data now! I'll update
> this topic once the code is up on GitHub ; )
>
> Thank you very much.
>
> On Tue, Jul 26, 2016 at 12:48 PM Peter Damoc  wrote:
>
>> OK,
>>
>> So, first, you had a typo in the decoder. it says "chidren" instead
>> of "children"
>>
>> This is why it is better to first debug the decoder with fake but valid
>> data and then move to retrieve the data from a live source.
>>
>> You do this by just prettifying the json and pasting it into a triple
>> quote string value.
>> And then you use Json.Decode.decodeString with this string value and
>> inspect the result using Debug.log
>>
>> Here is how I modified your model to inspect:
>>
>>
>> decodeJson =
>> let
>> data =
>> Debug.log "" (Json.decodeString decodeNews json_data)
>> in
>> Result.withDefault [] data
>>
>>
>> model : Model
>> model =
>> { news = decodeJson }
>>
>>
>> I've used only the first two items from the json because it seams to
>> trigger another error.
>> I don't have time to investigate further but it seams that the Json
>> library considers the JSON invalid and it looks like it's happening around
>> stuff like this:
>>
>> "content":"iframe class="embedly-embed"
>>
>>
>>
>>
>>
>> On Tue, Jul 26, 2016 at 12:33 PM, Eduardo Cuducos 
>> wrote:
>>
>>> Ow, sorry — thanks for letting me know, Peter.
>>> Here are the correct links:
>>>
>>>- Original JSON: https://www.reddit.com/search.json?q=subreddit:elm
>>>- My code so far:
>>>https://gist.github.com/cuducos/479ff955e3a8e18616f1905ae0a38774
>>>
>>> Peter, if I create a small JSON should I put it in a (local) HTTP or
>>> Json.Decoder loads from the file system?
>>>
>>> Many thanks,
>>>
>>> On Tue, Jul 26, 2016 at 10:47 AM Peter Damoc  wrote:
>>>
 The links you tried to post are broken.

 Have you tried creating a small sample JSON to test your decoders on?



 On Tue, Jul 26, 2016 at 11:17 AM, Eduardo Cuducos 
 wrote:

> Hi all,
>
> I'm tryind to parse Reddit JSON
> <#m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>  but I think I'm failing at the Json.Decoder— however I'm not sure if
> that really is the problem, and I don't know what else to try.
>
> The (ugly) JSON has this format (not so ugly after cleaned up, BTW):
>
> {
>   "data": {
> "children": [
>   {
> "data": {
>   "title": "Post title",
>   "url": "http://po.st/url;,
>   "domain": "po.st",
>   …
> },
> …
>   },
>   …
> ],
> …
>   }
>   …}
>
> I want to parse the title, url and domain inside data.children[i].data
>  (where i stands for each element of the list/array) in news list from
> my Elm model:
>
> type alias NewsItem =
> { title : String
> , url : String
> , domain : String
> }
> type alias Model =
> { news : List NewsItem }
>
> I've tried this without success:
>
> decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
> Json.object3 NewsItem
> (Json.at ["data", "title"] Json.string)
> (Json.at ["data", "url"] Json.string)
> (Json.at ["data", "domain"] Json.string)
> decodeNews : Json.Decoder (List NewsItem)decodeNews =
> Json.at ["data", "chidren"] (Json.list decodeNewsItem)
>
> The compiler throws no error at all, but once I open it (either with
> elm-reactor or the HTML from elm-make) the screen is blank (no
> errors, but no posts actually loaded from Reddit):
>
> What am I doing wrong? The full Elm script, with Task and init is here
> <#m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
> .
>
> Many thanks,
>
> Eduardo Cuducos
> http://cuducos.me
> <#m_5846310240132638687_m_857763608865669842_m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>
 --
> You received this message because you are subscribed to the Google
> Groups "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to 

Re: [elm-discuss] Parsing JSON — one more victim

2016-07-26 Thread Peter Damoc
OK,

So, first, you had a typo in the decoder. it says "chidren" instead
of "children"

This is why it is better to first debug the decoder with fake but valid
data and then move to retrieve the data from a live source.

You do this by just prettifying the json and pasting it into a triple quote
string value.
And then you use Json.Decode.decodeString with this string value and
inspect the result using Debug.log

Here is how I modified your model to inspect:


decodeJson =
let
data =
Debug.log "" (Json.decodeString decodeNews json_data)
in
Result.withDefault [] data


model : Model
model =
{ news = decodeJson }


I've used only the first two items from the json because it seams to
trigger another error.
I don't have time to investigate further but it seams that the Json library
considers the JSON invalid and it looks like it's happening around stuff
like this:

"content":"iframe class="embedly-embed"





On Tue, Jul 26, 2016 at 12:33 PM, Eduardo Cuducos  wrote:

> Ow, sorry — thanks for letting me know, Peter.
> Here are the correct links:
>
>- Original JSON: https://www.reddit.com/search.json?q=subreddit:elm
>- My code so far:
>https://gist.github.com/cuducos/479ff955e3a8e18616f1905ae0a38774
>
> Peter, if I create a small JSON should I put it in a (local) HTTP or
> Json.Decoder loads from the file system?
>
> Many thanks,
>
> On Tue, Jul 26, 2016 at 10:47 AM Peter Damoc  wrote:
>
>> The links you tried to post are broken.
>>
>> Have you tried creating a small sample JSON to test your decoders on?
>>
>>
>>
>> On Tue, Jul 26, 2016 at 11:17 AM, Eduardo Cuducos 
>> wrote:
>>
>>> Hi all,
>>>
>>> I'm tryind to parse Reddit JSON
>>> <#m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>>  but I think I'm failing at the Json.Decoder— however I'm not sure if
>>> that really is the problem, and I don't know what else to try.
>>>
>>> The (ugly) JSON has this format (not so ugly after cleaned up, BTW):
>>>
>>> {
>>>   "data": {
>>> "children": [
>>>   {
>>> "data": {
>>>   "title": "Post title",
>>>   "url": "http://po.st/url;,
>>>   "domain": "po.st",
>>>   …
>>> },
>>> …
>>>   },
>>>   …
>>> ],
>>> …
>>>   }
>>>   …}
>>>
>>> I want to parse the title, url and domain inside data.children[i].data
>>> (where i stands for each element of the list/array) in news list from
>>> my Elm model:
>>>
>>> type alias NewsItem =
>>> { title : String
>>> , url : String
>>> , domain : String
>>> }
>>> type alias Model =
>>> { news : List NewsItem }
>>>
>>> I've tried this without success:
>>>
>>> decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
>>> Json.object3 NewsItem
>>> (Json.at ["data", "title"] Json.string)
>>> (Json.at ["data", "url"] Json.string)
>>> (Json.at ["data", "domain"] Json.string)
>>> decodeNews : Json.Decoder (List NewsItem)decodeNews =
>>> Json.at ["data", "chidren"] (Json.list decodeNewsItem)
>>>
>>> The compiler throws no error at all, but once I open it (either with
>>> elm-reactor or the HTML from elm-make) the screen is blank (no errors,
>>> but no posts actually loaded from Reddit):
>>>
>>> What am I doing wrong? The full Elm script, with Task and init is here
>>> <#m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>> .
>>>
>>> Many thanks,
>>>
>>> Eduardo Cuducos
>>> http://cuducos.me
>>> <#m_3447146638404007097_m_-4208559428017899689_m_1784857688894315202_m_-844639499985301489_>
>>>
>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Elm Discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to elm-discuss+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> There is NO FATE, we are the creators.
>> blog: http://damoc.ro/
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to elm-discuss+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit 

Re: [elm-discuss] Parsing JSON — one more victim

2016-07-26 Thread Peter Damoc
The links you tried to post are broken.

Have you tried creating a small sample JSON to test your decoders on?



On Tue, Jul 26, 2016 at 11:17 AM, Eduardo Cuducos  wrote:

> Hi all,
>
> I'm tryind to parse Reddit JSON
> <#m_1784857688894315202_m_-844639499985301489_> but I think I'm failing
> at the Json.Decoder— however I'm not sure if that really is the problem,
> and I don't know what else to try.
>
> The (ugly) JSON has this format (not so ugly after cleaned up, BTW):
>
> {
>   "data": {
> "children": [
>   {
> "data": {
>   "title": "Post title",
>   "url": "http://po.st/url;,
>   "domain": "po.st",
>   …
> },
> …
>   },
>   …
> ],
> …
>   }
>   …}
>
> I want to parse the title, url and domain inside data.children[i].data
> (where i stands for each element of the list/array) in news list from my
> Elm model:
>
> type alias NewsItem =
> { title : String
> , url : String
> , domain : String
> }
> type alias Model =
> { news : List NewsItem }
>
> I've tried this without success:
>
> decodeNewsItem : Json.Decoder NewsItemdecodeNewsItem =
> Json.object3 NewsItem
> (Json.at ["data", "title"] Json.string)
> (Json.at ["data", "url"] Json.string)
> (Json.at ["data", "domain"] Json.string)
> decodeNews : Json.Decoder (List NewsItem)decodeNews =
> Json.at ["data", "chidren"] (Json.list decodeNewsItem)
>
> The compiler throws no error at all, but once I open it (either with
> elm-reactor or the HTML from elm-make) the screen is blank (no errors,
> but no posts actually loaded from Reddit):
>
> What am I doing wrong? The full Elm script, with Task and init is here
> <#m_1784857688894315202_m_-844639499985301489_>.
>
> Many thanks,
>
> Eduardo Cuducos
> http://cuducos.me <#m_1784857688894315202_m_-844639499985301489_>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.