Skip to content

Commit 9948eee

Browse files
committed
update docs
1 parent 0951a0d commit 9948eee

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Diff for: README.md

+57
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,60 @@ Created by Mattias Jansson / Rampant Pixels - <http://www.rampantpixels.com>
66
Please consider our Patreon - https://patreon.com/rampantpixels
77

88
This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.
9+
10+
# Overview
11+
12+
Small in-place JSON parser without any allocation. Entry points for both
13+
standard JSON and simplified JSON data parsing. All character data must be
14+
in UTF-8 format.
15+
16+
Strings are not automatically unescaped. Use json_unescape/json_escape to
17+
perform unescaping and espacing of strings. Unescaping can be done in-place
18+
to avoid memory allocations.
19+
20+
Simplified JSON as parsed by this library has the following differences
21+
from standard JSON:
22+
- The equal sign = is used to define key-value pairs instead of the colon :
23+
- Quotes around string keys in key-value pairs are optional, unless you need
24+
the key to contain either whitespace or the equal sign =
25+
- Commas are optional in object and array definitions
26+
- Each SJSON file is always interpreted as a definition for a single object.
27+
You can think of this as an implicit set of curly quotes { ... } that surround
28+
the contents of the file
29+
30+
Kudos to Niklas Gray for SJSON syntax,
31+
http://bitsquid.blogspot.se/2009/10/simplified-json-notation.html
32+
33+
# Usage
34+
35+
json_size_t
36+
json_parse(const char* buffer, json_size_t size,
37+
struct json_token_t* tokens, json_size_t capacity);
38+
39+
static json_size_t
40+
sjson_parse(const char* buffer, json_size_t size,
41+
struct json_token_t* tokens, json_size_t capacity);
42+
43+
Parse the given memory buffer as JSON or SJSON into the given token array of
44+
given capacity. Returns the number of parsed tokens, which can be greater
45+
than the supplied capacity to indicate the need for a larger array.
46+
47+
String identifiers and values are not unescaped. This must be performed manually
48+
on each string of interest.
49+
50+
static json_size_t
51+
json_unescape(char* buffer, json_size_t capacity, const char* string, json_size_t length);
52+
53+
Unescape a JSON identifier or value string. Buffer can be
54+
pointing to same memory area as string (in-place unescaping).
55+
56+
static json_size_t
57+
json_escape(char* buffer, json_size_t capacity, const char* string, json_size_t length);
58+
59+
Escape a JSON identifier or value string. Buffer can NOT be
60+
pointing to same memory area as string.
61+
62+
static bool
63+
json_string_equal(const char* rhs, size_t rhs_length, const char* lhs, size_t lhs_length);
64+
65+
Utility function to do bounded string compare.

0 commit comments

Comments
 (0)