https://github.com/follgad/zig-wasm-parser
Experimenting with WASM compilation from Zig
https://github.com/follgad/zig-wasm-parser
zig
Last synced: about 1 month ago
JSON representation
Experimenting with WASM compilation from Zig
- Host: GitHub
- URL: https://github.com/follgad/zig-wasm-parser
- Owner: FOLLGAD
- Created: 2024-09-02T21:17:29.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-08T23:21:49.000Z (over 1 year ago)
- Last Synced: 2025-03-09T00:20:49.629Z (over 1 year ago)
- Topics: zig
- Language: JavaScript
- Homepage: https://wasm-test.ahlback-emil.workers.dev/
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Partial-JSON parser
A "partial" JSON parser for WASM.
## Why?
LLM stream parsing is hard. Parsers are often used to extract data from unstructured text.
One of the most common data formats is JSON, and while it's streaming, it might look like this:
```json
{
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "123
```
Since this is not valid JSON, it is difficult to extract the data, especially multiple times a second in-browser while waiting for the LLM response.
What Partial-JSON does is it parses the JSON in a streaming fashion, and returns a valid JSON object with correct syntax,
letting you display the available data real-time to the user.
For the above input, Partial-JSON would return:
```json
{
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345"
}
}
```
## Fast
The parser is implemented in Zig, and compiled to WebAssembly.
It is able to parse and correct a 50kb JSON document in 1.3ms.
## Building
```bash
$ zig build zig build -Dtarget=wasm32-wasi
```
## Demo
Check [the demo](https://wasm-test.ahlback-emil.workers.dev) for a live demo.
Also found in the [example](./example) folder.