Skip to content

Commit

Permalink
Better documentation (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamesbarford authored Aug 8, 2023
1 parent 658ea2b commit 5cec2e1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
24 changes: 24 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2023, James W M Barford-Evans <jamesbarfordevans at gmail dot com>

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ JSON parsing simplified.

Easy JSON is a lightweight and fast JSON parser with an emphasis on ease of use
for parsing and accessing properties in the parsed JSON. I was wanting something
that had a small surface area, solid error handling with clear errors and a `jq`
like syntax for simplifying accessing properties off JSON.
that had a small surface area, solid error handling and a `jq` like syntax for
simplifying accessing properties off JSON.

The is error handling and reporting suitable for use with multiple threads as
The error state is unique per parsed JSON. Thus if you are parsing mulitple
Expand Down Expand Up @@ -53,6 +53,32 @@ json *jsonParseWithLenAndFlags(char *raw_json, size_t buflen, int flags);
- `JSON_STRNUM_FLAG` is avalible for parsing both floats and integers as
strings.

## Getters & Typechecking
The following will return `1` if the `json *` is not `NULL` and there is a match
on the type:

```c
int jsonIsObject(json *j);
int jsonIsArray(json *j);
int jsonIsNull(json *j);
int jsonIsBool(json *j);
int jsonIsString(json *j);
int jsonIsInt(json *j);
int jsonIsFloat(json *j);
```
And the following for getting a value from a `json *`:
```c
json *jsonGetObject(json *J);
json *jsonGetArray(json *J);
void *jsonGetNull(json *J);
int jsonGetBool(json *J);
char *jsonGetString(json *J);
ssize_t jsonGetInt(json *J);
double jsonGetFloat(json *J);
```

### NULL
A legitimate JSON NULL is parsed to `JSON_SENTINAL` not c's `NULL`. You can use
the helper `jsonIsNull()` to determine this.
Expand Down
10 changes: 5 additions & 5 deletions json.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ typedef enum JSON_ERRNO {
JSON_EOF,
} JSON_ERRNO;

char *jsonGetString(json *J);
double jsonGetFloat(json *J);
ssize_t jsonGetInt(json *J);
json *jsonGetArray(json *J);
json *jsonGetObject(json *J);
int jsonGetBool(json *J);
json *jsonGetArray(json *J);
void *jsonGetNull(json *J);
int jsonGetBool(json *J);
char *jsonGetString(json *J);
ssize_t jsonGetInt(json *J);
double jsonGetFloat(json *J);

int jsonIsObject(json *j);
int jsonIsArray(json *j);
Expand Down

0 comments on commit 5cec2e1

Please sign in to comment.