Skip to content

Commit

Permalink
Merge branch 'main' of github.com:liquidaty/json_writer into main
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidaty committed Sep 1, 2021
2 parents e156e91 + b566f4f commit 1713e6c
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,50 @@
# json_writer
json writer in C, MIT license
### jsonwriter: small, fast and permissively-license JSON writer written in C


#### Why do we need this?

This library was designed to meet the following requirements:

* small
* fast
* memory-efficient
* supports full range of UTF8
* written in C, portable, and permissively licensed
* thread safe
* supports custom write functions and write targets (e.g. write to network or pipe
or to custom buffer using some custom write function)

The last item was the most difficult to find, but was indispensible for versatile
reusability (for example, maybe we will not know, until dynamically at runtime, whether
we want to write our JSON to stdout, stderr, another file, a network pipe, or just
feed that back into some other process in a chain of data processing.

#### How to use

##### create a handle
Write either to a file, or provide your own `fwrite`-like function and target:

```
jsonwriter_handle jsonwriter_new_file(FILE *f);
jsonwriter_handle jsonwriter_new(
size_t (*write)(const void *, size_t, size_t, void *),
void *write_arg
);
```

e.g. `jsonwriter_handle h = jsonwriter_new(fwrite, stdout)`

##### write your JSON
For example:
```
jsonwriter_start_object(h);
jsonwriter_object_key(h, "hello");
jsonwriter_str(h, "there!");
jsonwriter_end(h);
```

##### clean up

`jsonwriter_delete(h)`

### Enjoy!

0 comments on commit 1713e6c

Please sign in to comment.