Skip to content

Commit

Permalink
Add API information to the README file
Browse files Browse the repository at this point in the history
  • Loading branch information
st235 committed Jun 29, 2024
1 parent 7e640c3 commit f3cc729
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,59 @@ See more in [`sample`](./sample/)

## Exploring the API

### Create Json Object
Everything you may expect is implemented (most likely 😅).

### Types

JSON specification declares 4 types and 3 literals:
- Literals
- `null`
- `true`
- `false`
- Types
- `number`
- `string`
- `array`
- `object`

All json values are conform to specially defined [`json::Json` type](./include/json.h).
To check for those literals and types `Json` defines special **boolean methods**:

- `Json#isNull`
- `Json#isBool`
- `Json#isNumber`
- `Json#isString`
- `Json#isArray`
- `Json#isObject`

Almost all `is` methods (except `isNull`) has corresponding `as` methods to safely get the content of json file:

- `asBool` -> returns `bool`
- `asNumber` -> `double`
- `asString` -> `std::string`
- `asArray` -> `std::vector<Json>`
- `asObject` -> `std::unordered_map<std::string, Json>`

### Create `Json` object from `std::string`

```cpp
#include "json.h"

...

const auto& json = json::Json::fromJson(file_context);
std::string json_text = ...
const auto& json = json::Json::fromJson(json_text);

...
```

### Declare `Json` object

```cpp
json::Json json = {
std::make_pair("a", json::Json({ json::Json(true), json::Json("b") })),
std::make_pair("b", json::Json(129.1))
}
```


Expand Down

0 comments on commit f3cc729

Please sign in to comment.