@honungsburk/kombo-json
v1.0.2
Published
A json parser built on top of kombo
Downloads
3
Maintainers
Readme
Kombo-JSON
A JSON parser that is built on top of Kombo, a parser combinator library.
Goals
For most purposes, I recommend using javascript's built-in JSON parser (JSON.parse
) but if you need better error messages this library could be of interest to you. It also serves as an example of how to build a more complicated parser using Kombo.
Stability
the core
module might have some function signatures or names changed so avoid relying on it.
Everything that is exported from the index
module I'll try to keep stable.
Example
import * as KomboJson from "@honungsburk/kombo-json";
const jsonString = JSON.stringify({
hello: "world",
});
/**
* Returns a result object that is either Ok or Err. You'll find the full API in the
* [kombo documentation](https://frankhampusweslien.com/kombo/modules/Result.html)
*/
const helloObjectResult = KomboJson.parser.run(jsonString);
if (helloObjectResult.isOk) {
console.log(helloObject.hello === "world");
// > true
}
Links
Further work
- Improve error messages
- Add even more tests
Development
We use golden tests to catch regressions in the error messages. But that means that if you improve the error messages you might need to
update the tests. You do this by running the tests using the command npm run test -- -u
. It will update all golden tests to use the current snapshot.