.TH "cereal::JSONOutputArchive" 3 "Mon Oct 26 2026 02:55:37" "cereal" \" -*- nroff -*- .ad l .nh .SH NAME cereal::JSONOutputArchive \- An output archive designed to save data to JSON\&. .SH SYNOPSIS .br .PP .PP \fR#include \fP .PP Inherits \fBcereal::OutputArchive< JSONOutputArchive >\fP, and \fBcereal::traits::TextArchive\fP\&. .SS "Classes" .in +1c .ti -1c .RI "class \fBOptions\fP" .br .RI "A class containing various advanced options for the JSON archive\&. " .in -1c .SS "Public Member Functions" .PP .RI "\fBCommon Functionality\fP" .br Common use cases for directly interacting with an \fBJSONOutputArchive\fP .PP .in +1c .in +1c .ti -1c .RI "\fBJSONOutputArchive\fP (std::ostream &stream, \fBOptions\fP const &options=\fBOptions::Default\fP())" .br .RI "Construct, outputting to the provided stream\&. " .ti -1c .RI "\fB~JSONOutputArchive\fP () \fBCEREAL_NOEXCEPT\fP" .br .RI "Destructor, flushes the JSON\&. " .ti -1c .RI "void \fBsaveBinaryValue\fP (const void *data, size_t size, const char *name=nullptr)" .br .RI "Saves some binary data, encoded as a base64 string, with an optional name\&. " .in -1c .in -1c Public Member Functions inherited from \fBcereal::OutputArchive< JSONOutputArchive >\fP .in +1c .ti -1c .RI "\fBOutputArchive\fP (\fBJSONOutputArchive\fP *const derived)" .br .RI "Construct the output archive\&. " .ti -1c .RI "\fBOutputArchive\fP & \fBoperator=\fP (\fBOutputArchive\fP const &)=delete" .br .ti -1c .RI "\fBJSONOutputArchive\fP & \fBoperator()\fP (Types &&\&.\&.\&. args)" .br .RI "Serializes all passed in data\&. " .ti -1c .RI "void \fBserializeDeferments\fP ()" .br .RI "Serializes any data marked for deferment using defer\&. " .ti -1c .RI "std::uint32_t \fBregisterSharedPointer\fP (const std::shared_ptr< const void > &sharedPointer)" .br .RI "Registers a shared pointer with the archive\&. " .ti -1c .RI "std::uint32_t \fBregisterPolymorphicType\fP (char const *name)" .br .RI "Registers a polymorphic type name with the archive\&. " .in -1c .in +1c .ti -1c .RI "\fBJSONOutputArchive\fP & \fBoperator&\fP (T &&arg)" .br .RI "Serializes passed in data\&. " .in -1c .in +1c .ti -1c .RI "\fBJSONOutputArchive\fP & \fBoperator<<\fP (T &&arg)" .br .RI "Serializes passed in data\&. " .in -1c Public Member Functions inherited from \fBcereal::detail::OutputArchiveBase\fP .in +1c .ti -1c .RI "\fBOutputArchiveBase\fP (OutputArchiveBase &&) \fBCEREAL_NOEXCEPT\fP" .br .ti -1c .RI "OutputArchiveBase & \fBoperator=\fP (OutputArchiveBase &&) \fBCEREAL_NOEXCEPT\fP" .br .in -1c .SS "Internal Functionality" Functionality designed for use by those requiring control over the inner mechanisms of the \fBJSONOutputArchive\fP .in +1c .ti -1c .RI "void \fBstartNode\fP ()" .br .RI "Starts a new node in the JSON output\&. " .ti -1c .RI "void \fBfinishNode\fP ()" .br .RI "Designates the most recently added node as finished\&. " .ti -1c .RI "void \fBsetNextName\fP (const char *name)" .br .RI "Sets the name for the next node created with startNode\&. " .ti -1c .RI "void \fBsaveValue\fP (bool b)" .br .RI "Saves a bool to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (int i)" .br .RI "Saves an int to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (unsigned u)" .br .RI "Saves a uint to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (int64_t i64)" .br .RI "Saves an int64 to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (uint64_t u64)" .br .RI "Saves a uint64 to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (double d)" .br .RI "Saves a double to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (std::string const &s)" .br .RI "Saves a string to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (char const *s)" .br .RI "Saves a const char * to the current node\&. " .ti -1c .RI "void \fBsaveValue\fP (std::nullptr_t)" .br .RI "Saves a nullptr to the current node\&. " .ti -1c .RI "template::value, !std::is_same< T, int >::value, !std::is_same< T, std::int64_t >::value > = traits::sfinae> void \fBsaveValue\fP (T t)" .br .RI "Serialize a long if it would not be caught otherwise\&. " .ti -1c .RI "template::value, !std::is_same< T, unsigned >::value, !std::is_same< T, std::uint64_t >::value > = traits::sfinae> void \fBsaveValue\fP (T t)" .br .RI "Serialize an unsigned long if it would not be caught otherwise\&. " .ti -1c .RI "template::value, !std::is_same< T, long >::value, !std::is_same< T, unsigned long >::value, !std::is_same< T, std::int64_t >::value, !std::is_same< T, std::uint64_t >::value,(sizeof(T) >=sizeof(long double)||sizeof(T) >=sizeof(long long))> = traits::sfinae> void \fBsaveValue\fP (T const &t)" .br .RI "Save exotic arithmetic as strings to current node\&. " .ti -1c .RI "void \fBwriteName\fP ()" .br .RI "Write the name of the upcoming node and prepare object/array state\&. " .ti -1c .RI "void \fBmakeArray\fP ()" .br .RI "Designates that the current node should be output as an array, not an object\&. " .in -1c .SS "Additional Inherited Members" .in +1c .ti -1c .RI "using \fBis_loading\fP" .br .RI "Indicates this archive is not intended for loading\&. " .in -1c .in +1c .ti -1c .RI "using \fBis_saving\fP" .br .RI "Indicates this archive is intended for saving\&. " .in -1c .SH "Detailed Description" .PP An output archive designed to save data to JSON\&. This archive uses RapidJSON to build serialize data to JSON\&. .PP JSON archives provides a human readable output but at decreased performance (both in time and space) compared to binary archives\&. .PP JSON archives are only guaranteed to finish flushing their contents upon destruction and should thus be used in an RAII fashion\&. .PP JSON benefits greatly from name-value pairs, which if present, will name the nodes in the output\&. If these are not present, each level of the output will be given an automatically generated delimited name\&. .PP The precision of the output archive controls the number of decimals output for floating point numbers and should be sufficiently large (i\&.e\&. at least 20) if there is a desire to have binary equality between the numbers output and those read in\&. In general you should expect a loss of precision when going from floating point to text and back\&. .PP JSON archives do not output the size information for any dynamically sized structure and instead infer it from the number of children for a node\&. This means that data can be hand edited for dynamic sized structures and will still be readable\&. This is accomplished through the \fBcereal::SizeTag\fP object, which will cause the archive to output the data as a JSON array (e\&.g\&. marked by [] instead of {}), which indicates that the container is variable sized and may be edited\&. .SH "Constructor & Destructor Documentation" .PP .SS "cereal::JSONOutputArchive::JSONOutputArchive (std::ostream & stream, \fBOptions\fP const & options = \fR\fBOptions::Default\fP()\fP)\fR [inline]\fP" .PP Construct, outputting to the provided stream\&. .PP \fBParameters\fP .RS 4 \fIstream\fP The stream to output to\&. .br \fIoptions\fP The JSON specific options to use\&. See the \fBOptions\fP struct for the values of default parameters .RE .PP .SH "Member Function Documentation" .PP .SS "void cereal::JSONOutputArchive::saveBinaryValue (const void * data, size_t size, const char * name = \fRnullptr\fP)\fR [inline]\fP" .PP Saves some binary data, encoded as a base64 string, with an optional name\&. This will create a new node, optionally named, and insert a value that consists of the data encoded as a base64 string .SS "template::value, !std::is_same< T, long >::value, !std::is_same< T, unsigned long >::value, !std::is_same< T, std::int64_t >::value, !std::is_same< T, std::uint64_t >::value,(sizeof(T) >=sizeof(long double)||sizeof(T) >=sizeof(long long))> = traits::sfinae> void cereal::JSONOutputArchive::saveValue (T const & t)\fR [inline]\fP" .PP Save exotic arithmetic as strings to current node\&. Handles long long (if distinct from other types), unsigned long (if distinct), and long double .SS "void cereal::JSONOutputArchive::startNode ()\fR [inline]\fP" .PP Starts a new node in the JSON output\&. The node can optionally be given a name by calling setNextName prior to creating the node .PP Nodes only need to be started for types that are themselves objects or arrays .SS "void cereal::JSONOutputArchive::writeName ()\fR [inline]\fP" .PP Write the name of the upcoming node and prepare object/array state\&. Since writeName is called for every value that is output, regardless of whether it has a name or not, it is the place where we will do a deferred check of our node state and decide whether we are in an array or an object\&. .PP The general workflow of saving to the JSON archive is: .PP .IP "1." 4 (optional) Set the name for the next node to be created, usually done by an NVP .IP "2." 4 Start the node .IP "3." 4 (if there is data to save) Write the name of the node (this function) .IP "4." 4 (if there is data to save) Save the data (with saveValue) .IP "5." 4 Finish the node .PP .SH "Author" .PP Generated automatically by Doxygen for cereal from the source code\&.