A lightweight, modular JSON parser written in C. It provides a clean API to tokenize, parse, and manage JSON objects, arrays, and values with safe memory handling.
- Project Structure
- Features
- Build Instructions
- Running Tests
- Usage Example
- Future Improvements
- License
.
├── include/
│ ├── lexer.h # Lexical analyzer (tokenizer)
│ ├── parser.h # Core parser and JSON data structures
│ ├── utility_func.h # Memory management + debugging helpers
│ ├── json_parser.h # High-level parsing interface
| └── stack.h
├── src/
│ ├── lexer.c
│ ├── parser.c
│ ├── utility_func.c
│ ├── json_parser.c
│ └── stack.c
├── main.c # Example entry point / test runner
├── makefile # Build script (Linux & Windows)
└── tests/ # JS tests (bun test)
- Tokenizes JSON strings into typed tokens.
- Parses into nested C data structures:
ObjectArrayValue(STRING,INTEGER,FLOAT,BOOLEAN,NULL, etc.)
- Safe memory deallocation helpers.
- Simple API for parsing JSON from strings.
Controlled by the project makefile:
make lin
# output: ./jpmake win
# output: ./jp-w.exe (requires MinGW)make clean # remove all builds
make clean-lin # remove Linux build only
make clean-win # remove Windows build onlyTests are written with bun test.
bun testNote: Ensure Bun is installed:
curl -fsSL https://bun.sh/install | bash
#include "json_parser.h"
int main() {
char* json_input = "{ \"name\": \"Alice\", \"age\": 25, \"student\": false }";
// Parse JSON string
ResponseKV result = json_parser(json_input);
// Work with result...
// e.g. traverse values, print types, etc.
// Free allocated memory
free_mem(result);
return 0;
}make lin
./jp- Better error reporting for malformed JSON.
- Support for streaming large JSON files.
- Helper functions for traversal/querying (like JSONPath).