Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rdpoor/jems
jems: a stream-based JSON serialized for embedded systems
https://github.com/rdpoor/jems
Last synced: 29 days ago
JSON representation
jems: a stream-based JSON serialized for embedded systems
- Host: GitHub
- URL: https://github.com/rdpoor/jems
- Owner: rdpoor
- License: mit
- Created: 2022-10-16T14:06:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-15T21:22:00.000Z (over 1 year ago)
- Last Synced: 2024-08-04T04:07:36.678Z (4 months ago)
- Language: C
- Homepage:
- Size: 23.4 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-embedded - jems
README
# jems
jems: a stream-based JSON serialized for embedded systems## About `jems`
`jems` is a compact, stream-based JSON serializer written in pure C for embedded
systems.`jems` makes it easy generate complex JSON structures, writing the results into
a buffer, string or stream. Specifically designed for embedded systems, `jems`
is:
* **compact**: one source file and one header file
* **portable**: written in pure C (with C++ compatible headers)
* **deterministic**: `jems` uses user-provided data structures and never calls
`malloc()`.
* **yours to use**: `jems` is covered under the permissive MIT License.`jems` derives much of its efficiency and small footprint by a philosophy of
trust: Rather than provide rigorous error checking of input parameters,
`jems` instead assumes that you provide valid parameters to function calls.## A Short Example
`jems` has a "emit characters as you go" philosophy, which allows you to
generate huge JSON structures with minimal memory usage. Here is a short
example:```
#include "jems.h"
#include
#include#define MAX_LEVEL 10 // how deeply nested the JSON structures can get
static jems_level_t jems_levels[MAX_LEVEL];
static jems_t jems;static void write_char(char ch, uintptr_t arg) {
fputc(ch, (FILE *)arg);
}int main(void) {
// initalize the jems object, using fputc() as the method for writing chars.
jems_init(&jems, jems_levels, MAX_LEVEL, write_char, (uintptr_t)stdout);jems_object_open(&jems); // start an object.
jems_string(&jems, "colors"); // first object key is "colors"
jems_array_open(&jems); // first object value is an array
jems_integer(&jems, 1); // ... with three numbers
jems_integer(&jems, 2);
jems_integer(&jems, 3);
jems_array_close(&jems); // end of the array
jems_string(&jems, "valid"); // second object key is "valid"
jems_true(&jems); // second object value is true
jems_object_close(&jems); // end of the object
}
```
This program will print
```
{"colors":[1,2,3],"valid":true}
```
on the standard output.