TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ dump()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
string_t nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::dump ( const int  indent = -1,
const char  indent_char = ' ',
const bool  ensure_ascii = false,
const error_handler_t  error_handler = error_handler_t::strict 
) const
inline

serialization

Serialization function for JSON values. The function tries to mimic Python's json.dumps() function, and currently supports its indent and ensure_ascii parameters.

Parameters
[in]indentIf indent is nonnegative, then array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. -1 (the default) selects the most compact representation.
[in]indent_charThe character to use for indentation if indent is greater than 0. The default is (space).
[in]ensure_asciiIf ensure_ascii is true, all non-ASCII characters in the output are escaped with \uXXXX sequences, and the result consists of ASCII characters only.
[in]error_handlerhow to react on decoding errors; there are three possible values: strict (throws and exception in case a decoding error occurs; default), replace (replace invalid UTF-8 sequences with U+FFFD), and ignore (ignore invalid UTF-8 sequences during serialization; all bytes are copied to the output unchanged).
Returns
string containing the serialization of the JSON value
Exceptions
type_error.316if a string stored inside the JSON value is not UTF-8 encoded and error_handler is set to strict
Note
Binary values are serialized as object containing two keys:
  • "bytes": an array of bytes as integers
  • "subtype": the subtype as integer or "null" if the binary has no subtype

@complexity Linear.

@exceptionsafety Strong guarantee: if an exception is thrown, there are no changes in the JSON value.

@liveexample{The following example shows the effect of different indent\, indent_char\, and ensure_ascii parameters to the result of the serialization.,dump}

See also
https://docs.python.org/2/library/json.html#json.dump
Since
version 1.0.0; indentation character indent_char, option ensure_ascii and exceptions added in version 3.0.0; error handlers added in version 3.4.0; serialization of binary values added in version 3.8.0.

Definition at line 20117 of file json.hpp.

20121 {
20122 string_t result;
20123 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
20124
20125 if (indent >= 0)
20126 {
20127 s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
20128 }
20129
20130 else
20131 {
20132 s.dump(*this, false, ensure_ascii, 0);
20133 }
20134
20135 return result;
20136 }
StringType string_t
a type for a string
Definition: json.hpp:18292