Skip to content

Comment on Parsing Text with Nomparent

Comments

In js/ts-land going from unknown type to known one normally means:

1. JSON.parse(...) string to json value

2. runtime assert it ie. with [0] which is a form of parsing but on json input as opposed to string parsing

In other words, when dealing with jsons, it's better to work on combinators over json values than combinators over string – the code is much more terse, natural and performant.

[0] https://github.com/appliedblockchain/assert-combinators

This can be seen as a form of tokenization, where the JSON objects are trees of tokens.

But that said, a more apt comparison is going from text to JSON in the first place (which is not trivial to do fast, and has issues when it comes to stream parsing).

There are enormous advantages to using JSON for storing structured application data though, mostly so you don't have to worry about writing a parser for it.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.