https://github.com/thehxdev/jacson
JSON parser and query engine library written in C, from scratch!
https://github.com/thehxdev/jacson
c json json-parser parser
Last synced: 10 months ago
JSON representation
JSON parser and query engine library written in C, from scratch!
- Host: GitHub
- URL: https://github.com/thehxdev/jacson
- Owner: thehxdev
- License: mit
- Created: 2024-03-24T07:17:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-28T09:52:56.000Z (11 months ago)
- Last Synced: 2025-03-24T09:11:30.813Z (10 months ago)
- Topics: c, json, json-parser, parser
- Language: C
- Homepage:
- Size: 108 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jacson
Jacson is a simple Json parsing library and query engine in C (in ~1100 LoC).
> [!WARNING]
> This project is just a simple json parser with simple query engine. Don't use this library for real programs.
## Features
- By not using recursion Jacson can handle deeply nested structures.
- Simple Public API
## Build
To build Jacson, you need a C compiler (`gcc` or `clang`), `cmake` and `make` installed on your system.
```bash
git clone --depth=1 --branch=main https://github.com/thehxdev/jacson
cd jacson
mkdir -p build && cmake -B build -S .
cmake --build build
```
Then you can use `libjacson.a` file for your projects in `build` directory and header files in `include` directory.
Or use `test` program in `build` directory to parse a json file and query data from that.
Take a look at `test/test.c` file to see how to use Jacson as a library.
## Query Syntax
Jacson has very simple query syntax to get data from AST (Parsed json data).
- Use `.` to seperate different parts of query.
- Use `[N]` syntax to show an array's index where N is a positive integer or 0.
### Example
Consider this json data:
```json
{
"message": "Hello World!",
"status": 200,
"ok": true,
"arr": [
true,
false,
56,
12.841,
{
"name": "thehxdev"
},
null
]
}
```
To get `thehxdev` string, you can use `arr.[4].name` query string.
> [!NOTE]
> Use `test` program in `build` directory to parse and query json files. Execute it with no arguments to get a help message.
## Architecture:
Jacson architecture
```
+------------------+
| Raw Json Data |
+---------+--------+
|
+---------v--------+
| Tokenizer |
+---------+--------+
|
+---------v--------+
| Validator |
+---------+--------+
|
+---------v--------+
| Parser |
+------------------+
```
## TODO
List of improvements and features to add:
- [x] Free all memory used by Jacson (without recursion)
- [x] Query engine for getting data from AST
- [x] Handle control characters in json strings
- [ ] Unicode (utf-8) support
- [ ] Handle control characters in query strings
- [ ] Change or add data to AST
- [ ] Better and more advanced query engine
- [ ] Documentation for Jacson's public API
- [ ] Error handling and reporting errors to top-level callers
- [ ] More advanced json syntax validation
- [ ] Lazy evaluation capabilities
- [ ] Write tests for each module