JSON Parser 100% From Scratch in Haskell (only 111 lines)

Channel:Tsoding · Length:1:50:06 · Published:2019-11-22 · Views:206638

Watch on YouTube

Summary

Tsoding live-codes a JSON parser from scratch in Haskell in about 111 lines, using only the standard library. It is an edited Twitch stream that explains the intuition behind parser combinators, functors, applicatives and monads.

Why HN recommends it

HN recommends it as a hands-on way to understand Haskell and parser combinators by watching a parser get built live.

this guy writes a json parser live, giving his intuition along the way. It's helped me immensely. — HN, 2020

Functional programming · Compilers, interpreters & program analysis

Subtitles (excerpt)

Um so, yeah. That's what we're doing today. We're going to try to implement a JSON parser in Haskell from scratch. No third-party dependencies. Absolutely no third-party dependencies. Only base. Only base, which is a standard library of Haskell. As many of you know, if you program the Haskell a little bit. And uh yeah. And it's going to be extremely small. Surprising. You will be surprised how easy it is. Well, relatively easy. Um to implement a JSON parser and how to implement parsers in general in Haskell. And it's no surprise that there is a lot of compilers and parsers implemented in Haskell because how easy it is to do that. Um How was the idea born? The idea was born on the bot development stream. And as a matter of fact, we implemented a parser of the DSL for custom commands on the stream for the bot. So, I decided to took that idea and applied you know to to something that majority of people are familiar with. For example, JSON parser. Can we implement a JSON parser using the same technique? And I was experimenting with that. It and it turned out yes, we can. And I was actually surprised how easy it is. Like yeah, you can just implement a JSON parser using the same technique.

On Hacker News

Nice to see Tsoding on the front page. He has another great video that covers a bunch of topics while making a JSON parser with only the Haskell standard library: [VIDEO] — ObiWanFrijoles, 2022-03
I have recently discovered [tsoding twitch channel]( [LINK] ) which describes itself as Recreational programming. The topics range from webassembly and Game development to functional programming in haskell and ocaml. Some of the interesting random things I found there include: * [a parser combinator in haskell]( [VIDEO] ) * [stack based language compiler in ocaml]( [LINK] ) You can find all the t… — ducaale, 2020-09
Agreed! I've been trying to learn haskell for a long time, and this guy writes a json parser live, giving his intuition along the way. It's helped me immensely. [VIDEO] — lubesGordi, 2020-07
To understand monads, I think it helps to know a language where expressing such a concept is more natural. Although I do not claim to know 100% what monads are yet, coming across these features made it easier for me to understand the concept a little bit. - Algebraic data types - OCaml's let expressions - F#'s computation expressions I also think that it is important to write something that natur… — ducaale, 2020-08

Related videos