https://github.com/buserror/libejson
lightweight and fast library for parsing JSON and Extended-JSON
https://github.com/buserror/libejson
Last synced: 4 months ago
JSON representation
lightweight and fast library for parsing JSON and Extended-JSON
- Host: GitHub
- URL: https://github.com/buserror/libejson
- Owner: buserror
- License: lgpl-3.0
- Created: 2012-06-27T07:45:15.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2020-12-23T13:32:52.000Z (about 5 years ago)
- Last Synced: 2025-01-12T06:04:12.014Z (about 1 year ago)
- Language: C
- Size: 78.1 KB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- License: COPYING
Awesome Lists containing this project
README
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}
span.Apple-tab-span {white-space:pre}
libejson, © Michel Pollet <buserror@gmail.com>
libejson is a library designed to parse JSON text (http://json.org/), as well as EJSON, an "extended" version of JSON that was designed to be more friendly for settings files, storage, and other uses like human interface description files.
libejson uses a simple "driver" (collection of callbacks) system, it parses the input and repeatedly calls your callbacks; your code is responsible for storing, allocating and generally "do stuff" with the parsed data.
libejson doesn't allocate memory generally, it will allocate a 128 byte buffer on the stack if it decodes base64 data (see below), otherwise it's footprint is minimal.
"Extended" JSON implements these extensions:
EJSON makes quoting node identifiers optional, if they don't contain spaces.
Normal JSON forces you to use syntax like '{ "hello" : "world" }' in EJSON, you can use '{ hello : "world" }'. This makes it easier to read/edit settings files by hand.
EJSON nodes can have flags/attributes
You can specify a list of words as a node "attribute". This allows flags to be passed to the host program for this particular node. It's especially important for files that describe human interface, or to allow easier debugging in some cases.
Syntax Example: { node_label (visible, translated) : "Bonjour" }
EJSON explicitly allows trailing comma in lists
JSON does not allow trailing comma in lists, which makes code that generate JSON more complicated for no reason, and also makes "patching" JSON files more difficult. EJSON allows trailing commas in objects and arrays.
Syntax Example: [0,1,2,]
EJSON allows binary data values
You can have arbitrary binary data in nodes, encoded in base64. This is often very useful to store small pieces of binary, small images, or other things embedded in a bigger file. The base64 values are delimited by % (percent) characters.
Syntax Example: { node : % WW91IGNhbiBlaXRoZXIgdXBsb2FkIGEgZmlsZ== % }
EJSON allows hexadecimal integer constants
hex constants are essential for files edited by hand.
Syntax Example: { node : 0xdeadbeef }
Example:
{
device : [
{
name : "Keyboard",
label (visible) : "105 keys keyboard",
flags : 0xcafef00d,
icon : %
RGVjb2RlIGJhc2U2NCBzdHJpbmdzIChiYXNlNjQgc3RyaW5nIGxvb2tzIGxpa2UgWVRNME5ab21J
ekkyT1RzbUl6TTBOVHVlWVE9PSkNCkRlY29kZSBhIGJhc2U2NCBlbmNvZGVkIGZpbGUgKGZvciBl
eGFtcGxlIElDTyBmaWxlcyBvciBmaWxlcyBmcm9tIE1JTUUgbWVzc2FnZSkNCkNvbnZlcnQgc291
cmNlIHRleHQgZGF0YSBmcm9tIHNldmVyYWwgY29kZSBwYQ== %
},
]
}