37#include <nfx/Containers.h>
38#include <nfx/string/StringBuilder.h>
223 inline Builder&
write( std::string_view key,
const std::string& value );
323 template <
typename T>
324 inline std::enable_if_t<
325 std::is_same_v<T, long> && !std::is_same_v<long, int> && !std::is_same_v<long, int64_t>,
327 write( std::string_view key, T value );
336 template <
typename T>
337 inline std::enable_if_t<
338 std::is_same_v<T, unsigned long> && !std::is_same_v<unsigned long, unsigned int> &&
339 !std::is_same_v<unsigned long, uint64_t>,
341 write( std::string_view key, T value );
349 template <
typename T>
350 inline std::enable_if_t<std::is_same_v<T, long long> && !std::is_same_v<long long, int64_t>,
Builder&>
write(
351 std::string_view key, T value );
360 template <
typename T>
361 inline std::enable_if_t<
362 std::is_same_v<T, unsigned long long> && !std::is_same_v<unsigned long long, uint64_t>,
364 write( std::string_view key, T value );
371 template <
typename T>
372 inline std::enable_if_t<
373 std::is_same_v<T, long> && !std::is_same_v<long, int> && !std::is_same_v<long, int64_t>,
383 template <
typename T>
384 inline std::enable_if_t<
385 std::is_same_v<T, unsigned long> && !std::is_same_v<unsigned long, unsigned int> &&
386 !std::is_same_v<unsigned long, uint64_t>,
395 template <
typename T>
396 inline std::enable_if_t<std::is_same_v<T, long long> && !std::is_same_v<long long, int64_t>,
Builder&>
write(
405 template <
typename T>
406 inline std::enable_if_t<
407 std::is_same_v<T, unsigned long long> && !std::is_same_v<unsigned long long, uint64_t>,
428 [[nodiscard]]
inline size_t size() const noexcept;
434 [[nodiscard]] inline
bool isEmpty() const noexcept;
455 [[nodiscard]] inline
size_t capacity() const noexcept;
462 [[nodiscard]] inline
size_t depth() const noexcept;
468 [[nodiscard]] inline
bool isValid() const noexcept;
506 inline void writeInt( int64_t value );
512 inline void writeUInt( uint64_t value );
518 inline void writeDouble(
double value );
524 inline void writeString( std::string_view str );
529 inline void writeNewlineAndIndent();
534 inline void writeCommaIfNeeded();
541 inline void writeDocument(
const Document& doc );
547 inline void writeDocumentArray(
const Array& array );
553 inline void writeDocumentObject(
const Object&
object );
555 string::StringBuilder m_buffer;
558 bool m_escapeNonAscii;
559 containers::StackVector<ContextFrame, 8> m_contextStack;
563#include "detail/Builder.inl"
JSON Document type with low-level and high-level APIs.
std::vector< std::pair< std::string, Document > > Object
Ordered map for JSON objects (preserves insertion order).
std::vector< Document > Array
Array for JSON arrays.
Builder & writeEndArray()
End writing a JSON array.
bool isEmpty() const noexcept
Check if builder is empty.
Builder & write(std::string_view key, std::string_view value)
Write a string value property.
Builder & reset()
Reset builder to initial state for reuse.
std::string toString()
Get the constructed JSON string.
Builder & write(std::string_view key, bool value)
Write a boolean value property.
std::enable_if_t< std::is_same_v< T, unsigned long long > &&!std::is_same_v< unsigned long long, uint64_t >, Builder & > write(std::string_view key, T value)
Write an unsigned long long integer value property (SFINAE overload for platforms where unsigned long...
Builder & writeKey(std::string_view key)
Write a property key before a nested object or array.
Builder & write(const std::string &value)
Write a string value in an array.
Builder & write(std::string_view key, float value)
Write a float value property.
std::enable_if_t< std::is_same_v< T, long > &&!std::is_same_v< long, int > &&!std::is_same_v< long, int64_t >, Builder & > write(std::string_view key, T value)
Write a long integer value property (SFINAE overload for platforms where long != int64_t).
std::enable_if_t< std::is_same_v< T, long long > &&!std::is_same_v< long long, int64_t >, Builder & > write(std::string_view key, T value)
Write a long long integer value property (SFINAE overload for platforms where long long !...
std::enable_if_t< std::is_same_v< T, unsigned long long > &&!std::is_same_v< unsigned long long, uint64_t >, Builder & > write(T value)
Write an unsigned long long integer value in an array (SFINAE overload for platforms where unsigned l...
Builder & write(std::string_view key, const Document &value)
Write a Document value property.
Builder & write(const Document &value)
Write a Document value in an array.
Builder & write(std::string_view key, int64_t value)
Write a 64-bit integer value property.
Builder & write(int64_t value)
Write a 64-bit integer value in an array.
Builder & write(std::string_view key, const char *value)
Write a string value property.
std::enable_if_t< std::is_same_v< T, long > &&!std::is_same_v< long, int > &&!std::is_same_v< long, int64_t >, Builder & > write(T value)
Write a long integer value in an array (SFINAE overload for platforms where long !...
size_t size() const noexcept
Get current JSON string size.
std::enable_if_t< std::is_same_v< T, long long > &&!std::is_same_v< long long, int64_t >, Builder & > write(T value)
Write a long long integer value in an array (SFINAE overload for platforms where long long !...
Builder & writeArray(std::string_view key, const Container &values)
Write a complete array from a STL container as object property.
std::string_view toStringView() const noexcept
Get non-destructive view of generated JSON.
Builder & write(int value)
Write an integer value in an array.
Builder & write(bool value)
Write a boolean value in an array.
Builder & write(std::string_view key, double value)
Write a double value property.
Builder & write(std::string_view key, const std::string &value)
Write a string value property.
bool isValid() const noexcept
Check if builder state is valid.
Builder & writeStartObject()
Start writing a JSON object.
Builder & write(const char *value)
Write a string value in an array.
Builder & write(uint64_t value)
Write an unsigned 64-bit integer value in an array.
Builder & write(std::string_view value)
Write a string value in an array.
Builder & write(float value)
Write a float value in an array.
Builder & reserve(size_t capacity)
Reserve buffer capacity.
Builder & write(std::string_view key, std::nullptr_t value)
Write a null value property.
Builder & writeStartArray()
Start writing a JSON array.
Builder & write(std::string_view key, unsigned int value)
Write an unsigned integer value property.
Builder & write(std::string_view key, uint64_t value)
Write an unsigned 64-bit integer value property.
Builder & writeRawJson(std::string_view rawJson)
Write raw JSON string directly to output.
std::enable_if_t< std::is_same_v< T, unsigned long > &&!std::is_same_v< unsigned long, unsigned int > &&!std::is_same_v< unsigned long, uint64_t >, Builder & > write(T value)
Write an unsigned long integer value in an array (SFINAE overload for platforms where unsigned long !...
Builder(Options options={ 0, 4096, false })
Constructor with options.
size_t capacity() const noexcept
Get current buffer capacity.
Builder & write(std::nullptr_t value)
Write a null value in an array.
Builder & writeEndObject()
End writing a JSON object.
Builder & write(double value)
Write a double value in an array.
size_t depth() const noexcept
Get current nesting depth.
Builder & write(unsigned int value)
Write an unsigned integer value in an array.
Builder & write(std::string_view key, int value)
Write an integer value property.
std::enable_if_t< std::is_same_v< T, unsigned long > &&!std::is_same_v< unsigned long, unsigned int > &&!std::is_same_v< unsigned long, uint64_t >, Builder & > write(std::string_view key, T value)
Write an unsigned long integer value property (SFINAE overload for platforms where unsigned long !...
Configuration options for Builder.
size_t bufferSize
Initial buffer capacity hint.
int indent
Indentation level (0 = compact, >0 = pretty print with N spaces per level).
bool escapeNonAscii
Escape non-ASCII UTF-8 characters as \uXXXX escape sequences.
Low-level JSON value storage type.
Concept for JSON container types only.