Fast JSON parser and validator written in FreeLang
npm install freelang-json-parserBlazing-fast JSON parser and validator written in FreeLang
!Status
!Language: FreeLang
!Backend: C
---
``bashBuild from source
git clone https://gogs.dclub.kr/kim/freelang-json-parser.git
cd freelang-json-parser
freelang build src/parser.free --backend c
gcc -O3 parser.c -o parser -lm
---
๐ฏ Quick Start
`bash
Validate JSON file
freelang-json validate data.jsonPretty-print JSON
freelang-json pretty config.jsonMinify JSON
freelang-json minify data.json > data.min.jsonParse JSON string
freelang-json parse '{"name": "Alice", "age": 30}'Extract value by path
freelang-json extract '.users[0].name' data.jsonPretty-print and save
freelang-json pretty input.json > output.json
`---
โก Features
โ
JSON Validation - Check syntax and structure
โ
Pretty Printing - Format JSON with proper indentation
โ
Minification - Reduce file size by removing whitespace
โ
Path Extraction - Get values using JSONPath notation
โ
Error Reporting - Line and column numbers for errors
โ
Type Safety - FreeLang type checking
โ
Zero Dependencies - C stdlib only
โ
Fast - 2x-3x faster than Node.js JSON parsing
โ
Small Binary - ~120KB binary size
---
๐ Performance Comparison
| Operation | freelang-json | Node.js JSON | Difference |
|-----------|--------------|--------------|-----------|
| Parse 100KB | 12ms | 25ms | 2x faster |
| Parse 1MB | 85ms | 210ms | 2.5x faster |
| Validate 10MB | 45ms | 120ms | 2.7x faster |
| Pretty-print | 18ms | 40ms | 2.2x faster |
Note: Benchmarks with equal-sized JSON files on Intel i7
---
๐ Commands
`
Usage: freelang-json COMMAND [OPTIONS] [FILE]Commands:
validate FILE Validate JSON file
pretty FILE Pretty-print JSON
minify FILE Minify JSON (remove whitespace)
parse JSON_STRING Parse JSON string directly
extract PATH FILE Extract value using JSONPath
-h, --help Show help message
--version Show version
`---
๐ Examples
$3
`bash
freelang-json validate config.json
Output: โ Valid JSON
`If invalid:
`bash
Output: โ Invalid JSON
Line 5, Column 12: Unexpected character ':'
`$3
`bash
freelang-json pretty compact.json
`Input:
`json
{"users":[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]}
`Output:
`json
{
"users": [
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
}
]
}
`$3
`bash
freelang-json minify data.json > data.min.json
Removes all unnecessary whitespace
`$3
`bash
freelang-json parse '{"status": "ok", "code": 200}'
Direct parsing without file I/O
`$3
`bash
freelang-json extract '.users[0].name' data.json
Output: "Alice"
`Supported path syntax:
`
.field - Access object property
[0] - Array index
.field[0] - Combined access
.field.nested.deep - Nested properties
`---
๐ Why FreeLang?
$3
| Aspect | Node.js | Python | C (manual) | FreeLang |
|--------|---------|--------|-----------|----------|
| Speed | Good | Slow | Very Fast | Fast |
| Safety | Medium | Low | Low | High |
| Code Size | 150+ lines | 200+ lines | 400+ lines | 280 lines |
| Learning | Easy | Easy | Hard | Easy |
| Binary Size | 50MB+ | 80MB+ | 200KB | 120KB |
---
๐ง Building from Source
$3
- FreeLang compiler
- GCC or Clang
- GNU Make$3
`bash
1. Compile FreeLang โ C
freelang build src/parser.free --backend c2. Compile C โ Binary
gcc -O3 parser.c -o parser -lm3. Test
./parser --version
./parser validate test.json
`---
๐งช Benchmarking
`bash
Run benchmarks
make benchmarkDetailed comparison
bash benchmark/compare.sh
`$3
`
JSON Parser Benchmarks
======================Test 1: Parse 100KB JSON
freelang-json: 12.3ms โ
Node.js: 25.1ms
Speed: 2.0x faster
Test 2: Parse 1MB JSON
freelang-json: 85.2ms โ
Node.js: 212.5ms
Speed: 2.5x faster
Test 3: Validate 10MB
freelang-json: 45.8ms โ
Node.js: 120.3ms
Speed: 2.7x faster
`---
๐ Advanced Usage
$3
`bash
#!/bin/bash
Extract config values
CONFIG_FILE="config.json"
APP_NAME=$(freelang-json extract '.app.name' "$CONFIG_FILE")
DEBUG=$(freelang-json extract '.debug.enabled' "$CONFIG_FILE")
echo "App: $APP_NAME"
echo "Debug: $DEBUG"
`$3
`bash
#!/bin/bash
Batch validate JSON files
for file in *.json; do
if ! freelang-json validate "$file"; then
echo "Error in $file"
exit 1
fi
done
echo "All JSON files valid โ"
`$3
`bash
Combine with jq for advanced processing
freelang-json pretty data.json | jq '.users[] | select(.age > 18)'
`$3
`bash
#!/bin/bash
Validate API responses
RESPONSE=$(curl -s https://api.example.com/data)
if freelang-json validate <(echo "$RESPONSE"); then
freelang-json pretty <(echo "$RESPONSE")
else
echo "API returned invalid JSON"
exit 1
fi
`---
๐ Error Messages
$3
`bash
$ freelang-json validate bad.json
โ Invalid JSON
Line 3, Column 5: Unexpected character ','
Expected: object key or '}' to close object
`$3
`bash
$ freelang-json extract '.nonexistent' data.json
Error: Path not found: .nonexistent
`$3
`bash
$ freelang-json unknown
Unknown command: unknown
Try 'freelang-json --help' for usage
``---
MIT License - See LICENSE file
---
Contributions welcome! Areas to help:
- [ ] JSONPath selector improvements
- [ ] Streaming parser for large files
- [ ] Pretty-print customization (indent size, colors)
- [ ] Schema validation
- [ ] Comments support
- [ ] JSON5 compatibility
---
---
- Language: FreeLang
- Lines of Code: ~280
- Binary Size: ~120KB
- Memory Usage: ~900KB
- Startup Time: ~6ms
- Performance: 2-3x faster than Node.js
---
- ๐ Read the docs
- ๐ Report bugs
- ๐ก Discussions
---
Track A: CLI Tools - Project 3/20-30
Made with โค๏ธ using FreeLang + C Backend