From f3cc729d7b575b4a5c84be81cf7f23676152f6a8 Mon Sep 17 00:00:00 2001 From: Alex Dadukin Date: Sat, 29 Jun 2024 18:59:41 +0100 Subject: [PATCH] Add API information to the README file --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d1809f..6e2a699 100644 --- a/README.md +++ b/README.md @@ -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` +- `asObject` -> `std::unordered_map` + +### 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)) +} ```