-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.txt
More file actions
132 lines (96 loc) · 3.72 KB
/
Copy pathREADME.txt
File metadata and controls
132 lines (96 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/////////////////////////////////////////////////////////////////////////////
// //
// stb_json - v1.7.19 (Aug 2025) //
// Single-file JSON parser/generator for C/C++ in the STB style //
// //
/////////////////////////////////////////////////////////////////////////////
----------------------------------------------
| _______ _____ _____ ___ _ _______ |
| |__ __/ ____| |_ _/ _ \| |/ / ____| |
| | | | (___ ______| || | | | ' /| __| |
| | | \___ \______| || | | | < | | |
| | | ____) | _| || |_| | . \| |____ |
| |_| |_____/ |_____\___/|_|\_\______| |
| |
----------------------------------------------
== ABOUT ==
A lightweight single-header JSON library for C/C++ that implements both parsing
and generation with full RFC compliance. Designed for simplicity, portability,
and efficiency in the tradition of Sean Barrett's stb libraries.
Created by Ferki (August 2025)
== FEATURES ==
✓ Single header file implementation
✓ No external dependencies
✓ Thread-safe error tracking
✓ Full JSON standard support (RFC 8259)
✓ Memory management hooks
✓ JSON Pointer (RFC 6901) support
✓ JSON Patch (RFC 6902) support
✓ JSON Merge Patch (RFC 7386) support
✓ File parsing utilities
✓ Efficient parsing and serialization
✓ Circular reference detection
✓ Unicode/UTF-8 validation
✓ Minification utility
✓ Fuzzer test harness
== USAGE ==
1. In ONE source file, add:
#define STB_JSON_IMPLEMENTATION
#include "stb_json.h"
2. In other files, just include normally:
#include "stb_json.h"
== BASIC EXAMPLE ==
const char* json = "{\"name\":\"John\",\"age\":30,\"cars\":[\"Ford\",\"BMW\"]}";
stb_json* root = stb_json_parse(json);
if (root) {
stb_json* name = stb_json_getobjectitem(root, "name");
printf("Name: %s\n", name->valuestring);
stb_json_delete(root);
}
== ADVANCED FEATURES ==
// JSON Pointer
stb_json* item = stb_json_utils_getpointer(root, "/cars/0");
// JSON Patch
stb_json* patches = stb_json_utils_generatepatches(source, target);
int result = stb_json_utils_applypatches(doc, patches);
// File parsing
stb_json* config = stb_json_parse_file("config.json");
// Minification
char json_str[] = "{ \"key\": \"value\" }";
stb_json_minify(json_str); // Becomes {"key":"value"}
== MEMORY MANAGEMENT ==
Custom allocators can be configured:
stb_json_hooks hooks = {
.malloc_fn = my_malloc,
.free_fn = my_free
};
stb_json_inithooks(&hooks);
== BUILDING ==
Just include the header! For testing:
1. Enable implementation in test file
2. Compile with:
clang -O2 -std=c99 test.c -o test
== TESTING ==
Includes built-in fuzzer harness:
./stb_json_fuzzer testcase.json
Or use the test runner:
./stb_json_test input.json
== VERSION HISTORY ==
v1.7.19 (2025-08-04)
- Initial public release
- Full RFC compliance
- Thread-safe error tracking
- File I/O utilities
== LICENSE ==
MIT License.
This software is free for any use.
== SUPPORT THE DEVELOPER ==
If you appreciate this software and use it in your projects,
please consider supporting its development:
[ https://ko-fi.com/ferki ]
Your donations help maintain and improve this library!
/////////////////////////////////////////////////////////////////////////////
// //
// "Simplicity is prerequisite for reliability." - Edsger Dijkstra //
// //
/////////////////////////////////////////////////////////////////////////////