Builds one JSON document.
More...
#include <json.hpp>
|
| | json_writer () |
| | An empty writer, with room for a typical document.
|
| |
| json_writer & | begin_object () |
| | Open an object.
|
| |
| json_writer & | end_object () |
| | Close the innermost object.
|
| |
| json_writer & | begin_array () |
| | Open an array.
|
| |
| json_writer & | end_array () |
| | Close the innermost array.
|
| |
| json_writer & | key (std::string_view name) |
| | Write an object key; the next call writes its value.
|
| |
| json_writer & | value (std::string_view text) |
| | Write a string value.
|
| |
| json_writer & | value (const char *text) |
| | Write a string value (keeps string literals from binding to bool).
|
| |
| json_writer & | value (bool b) |
| | Write a boolean.
|
| |
| json_writer & | value (std::nullptr_t) |
| | Write null.
|
| |
template<std::integral T>
requires (!std::same_as<T, bool> && !std::same_as<T, char> && !std::same_as<T, wchar_t> && !std::same_as<T, char8_t> && !std::same_as<T, char16_t> && !std::same_as<T, char32_t>) |
| json_writer & | value (T n) |
| | Write an integer.
|
| |
| json_writer & | value (double d) |
| | Write a number, in the shortest form that reads back exactly.
|
| |
| template<typename V > |
| json_writer & | field (std::string_view name, const V &v) |
| | Write a key and its value.
|
| |
| bool | complete () const noexcept |
| | Whether exactly one complete value has been written.
|
| |
| const std::string & | str () const |
| | The document.
|
| |
|
| static void | escape (std::string &out, std::string_view text) |
| | Append a JSON string literal for text to out.
|
| |
Builds one JSON document.
std::string text = w.
str();
Builds one JSON document.
json_writer & begin_object()
Open an object.
json_writer & key(std::string_view name)
Write an object key; the next call writes its value.
json_writer & field(std::string_view name, const V &v)
Write a key and its value.
json_writer & begin_array()
Open an array.
json_writer & value(std::string_view text)
Write a string value.
json_writer & end_object()
Close the innermost object.
const std::string & str() const
The document.
json_writer & end_array()
Close the innermost array.
Definition at line 48 of file json.hpp.
◆ json_writer()
| dasmig::core::json_writer::json_writer |
( |
| ) |
|
|
inline |
An empty writer, with room for a typical document.
Definition at line 52 of file json.hpp.
◆ begin_array()
| json_writer & dasmig::core::json_writer::begin_array |
( |
| ) |
|
|
inline |
Open an array.
- Returns
*this.
- Exceptions
-
| std::logic_error | Where a value is not allowed. |
Definition at line 88 of file json.hpp.
◆ begin_object()
| json_writer & dasmig::core::json_writer::begin_object |
( |
| ) |
|
|
inline |
Open an object.
- Returns
*this.
- Exceptions
-
| std::logic_error | Where a value is not allowed. |
Definition at line 61 of file json.hpp.
◆ complete()
| bool dasmig::core::json_writer::complete |
( |
| ) |
const |
|
inlinenoexcept |
Whether exactly one complete value has been written.
- Returns
- True when str() can be called.
Definition at line 217 of file json.hpp.
◆ end_array()
Close the innermost array.
- Returns
*this.
- Exceptions
-
| std::logic_error | If the innermost container is not an array. |
Definition at line 99 of file json.hpp.
◆ end_object()
| json_writer & dasmig::core::json_writer::end_object |
( |
| ) |
|
|
inline |
Close the innermost object.
- Returns
*this.
- Exceptions
-
| std::logic_error | If the innermost container is not an object, or a key has no value. |
Definition at line 73 of file json.hpp.
◆ escape()
| static void dasmig::core::json_writer::escape |
( |
std::string & |
out, |
|
|
std::string_view |
text |
|
) |
| |
|
inlinestatic |
Append a JSON string literal for text to out.
- Parameters
-
| out | Destination. |
| text | UTF-8 text. |
- Exceptions
-
| std::invalid_argument | If text is not valid UTF-8. |
Definition at line 235 of file json.hpp.
◆ field()
template<typename V >
| json_writer & dasmig::core::json_writer::field |
( |
std::string_view |
name, |
|
|
const V & |
v |
|
) |
| |
|
inline |
Write a key and its value.
- Parameters
-
| name | UTF-8 key. |
| v | The value (any type value() accepts). |
- Returns
*this.
Definition at line 209 of file json.hpp.
◆ key()
| json_writer & dasmig::core::json_writer::key |
( |
std::string_view |
name | ) |
|
|
inline |
Write an object key; the next call writes its value.
- Parameters
-
- Returns
*this.
- Exceptions
-
| std::logic_error | Outside an object or after another key. |
| std::invalid_argument | If name is not valid UTF-8. |
Definition at line 116 of file json.hpp.
◆ str()
| const std::string & dasmig::core::json_writer::str |
( |
| ) |
const |
|
inline |
The document.
- Returns
- The JSON text.
- Exceptions
-
| std::logic_error | If the document is incomplete. |
Definition at line 222 of file json.hpp.
◆ value() [1/6]
| json_writer & dasmig::core::json_writer::value |
( |
bool |
b | ) |
|
|
inline |
Write a boolean.
- Parameters
-
- Returns
*this.
Definition at line 149 of file json.hpp.
◆ value() [2/6]
| json_writer & dasmig::core::json_writer::value |
( |
const char * |
text | ) |
|
|
inline |
Write a string value (keeps string literals from binding to bool).
- Parameters
-
| text | Null-terminated UTF-8 text. |
- Returns
*this.
Definition at line 144 of file json.hpp.
◆ value() [3/6]
| json_writer & dasmig::core::json_writer::value |
( |
double |
d | ) |
|
|
inline |
Write a number, in the shortest form that reads back exactly.
- Parameters
-
- Returns
*this.
- Exceptions
-
| std::invalid_argument | If d is NaN or infinite (JSON has no representation for them). |
Definition at line 190 of file json.hpp.
◆ value() [4/6]
| json_writer & dasmig::core::json_writer::value |
( |
std::nullptr_t |
| ) |
|
|
inline |
Write null.
- Returns
*this.
Definition at line 159 of file json.hpp.
◆ value() [5/6]
| json_writer & dasmig::core::json_writer::value |
( |
std::string_view |
text | ) |
|
|
inline |
Write a string value.
- Parameters
-
- Returns
*this.
- Exceptions
-
| std::invalid_argument | If text is not valid UTF-8. |
Definition at line 133 of file json.hpp.
◆ value() [6/6]
template<std::integral T>
requires (!std::same_as<T, bool> && !std::same_as<T, char> && !std::same_as<T, wchar_t> && !std::same_as<T, char8_t> && !std::same_as<T, char16_t> && !std::same_as<T, char32_t>)
Write an integer.
- Template Parameters
-
| T | Integral type other than bool and the character types. |
- Parameters
-
- Returns
*this.
Definition at line 175 of file json.hpp.
The documentation for this class was generated from the following file: