cereal::JSONOutputArchive(3) Library Functions Manual cereal::JSONOutputArchive(3)

# [NAME](#NAME)

cereal::JSONOutputArchive - An output archive designed to save data to JSON.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;/home/build/include/cereal/archives/json.hpp&gt;

Inherits **cereal::OutputArchive&lt; JSONOutputArchive &gt;**, and **cereal::traits::TextArchive**.

## [Classes](#Classes)

class **Options**  
A class containing various advanced options for the JSON archive.

## [Public Member Functions](#Public_Member_Functions)

**Common Functionality**  
Common use cases for directly interacting with an **JSONOutputArchive**

**JSONOutputArchive** (std::ostream &stream, **Options** const &options=**Options::Default**())  
Construct, outputting to the provided stream. **~JSONOutputArchive** () **CEREAL\_NOEXCEPT**  
Destructor, flushes the JSON. void **saveBinaryValue** (const void \*data, size\_t size, const char \*name=nullptr)  
Saves some binary data, encoded as a base64 string, with an optional name.

Public Member Functions inherited from **cereal::OutputArchive&lt; JSONOutputArchive &gt;**  
**OutputArchive** (**JSONOutputArchive** \*const derived)  
Construct the output archive. **OutputArchive** & **operator=** (**OutputArchive** const &)=delete  
**JSONOutputArchive** & **operator()** (Types &&... args)  
Serializes all passed in data. void **serializeDeferments** ()  
Serializes any data marked for deferment using defer. std::uint32\_t **registerSharedPointer** (const std::shared\_ptr&lt; const void &gt; &sharedPointer)  
Registers a shared pointer with the archive. std::uint32\_t **registerPolymorphicType** (char const \*name)  
Registers a polymorphic type name with the archive.

**JSONOutputArchive** & **operator&** (T &&arg)  
Serializes passed in data.

**JSONOutputArchive** & **operator&lt;&lt;** (T &&arg)  
Serializes passed in data.

Public Member Functions inherited from **cereal::detail::OutputArchiveBase**  
**OutputArchiveBase** (OutputArchiveBase &&) **CEREAL\_NOEXCEPT**  
OutputArchiveBase & **operator=** (OutputArchiveBase &&) **CEREAL\_NOEXCEPT**

## [Internal Functionality](#Internal_Functionality)

Functionality designed for use by those requiring control over the inner mechanisms of the **JSONOutputArchive**  
void **startNode** ()  
Starts a new node in the JSON output. void **finishNode** ()  
Designates the most recently added node as finished. void **setNextName** (const char \*name)  
Sets the name for the next node created with startNode. void **saveValue** (bool b)  
Saves a bool to the current node. void **saveValue** (int i)  
Saves an int to the current node. void **saveValue** (unsigned u)  
Saves a uint to the current node. void **saveValue** (int64\_t i64)  
Saves an int64 to the current node. void **saveValue** (uint64\_t u64)  
Saves a uint64 to the current node. void **saveValue** (double d)  
Saves a double to the current node. void **saveValue** (std::string const &s)  
Saves a string to the current node. void **saveValue** (char const \*s)  
Saves a const char * to the current node. void **saveValue** (std::nullptr\_t)  
Saves a nullptr to the current node. template&lt;class T, traits::EnableIf&lt; std::is\_same&lt; T, long &gt;::value, !std::is\_same&lt; T, int &gt;::value, !std::is\_same&lt; T, std::int64\_t &gt;::value &gt; = traits::sfinae&gt; void **saveValue** (T t)  
Serialize a long if it would not be caught otherwise. template&lt;class T, traits::EnableIf&lt; std::is\_same&lt; T, unsigned long &gt;::value, !std::is\_same&lt; T, unsigned &gt;::value, !std::is\_same&lt; T, std::uint64\_t &gt;::value &gt; = traits::sfinae&gt; void **saveValue** (T t)  
Serialize an unsigned long if it would not be caught otherwise. template&lt;class T, traits::EnableIf&lt; std::is\_arithmetic&lt; T &gt;::value, !std::is\_same&lt; T, long &gt;::value, !std::is\_same&lt; T, unsigned long &gt;::value, !std::is\_same&lt; T, std::int64\_t &gt;::value, !std::is\_same&lt; T, std::uint64\_t &gt;::value,(sizeof(T) &gt;=sizeof(long double)||sizeof(T) &gt;=sizeof(long long))&gt; = traits::sfinae&gt; void **saveValue** (T const &t)  
Save exotic arithmetic as strings to current node. void **writeName** ()  
Write the name of the upcoming node and prepare object/array state. void **makeArray** ()  
Designates that the current node should be output as an array, not an object.

## [Additional Inherited Members](#Additional_Inherited_Members)

using **is\_loading**  
Indicates this archive is not intended for loading.

using **is\_saving**  
Indicates this archive is intended for saving.

# [Detailed Description](#Detailed_Description)

An output archive designed to save data to JSON.

This archive uses RapidJSON to build serialize data to JSON.

JSON archives provides a human readable output but at decreased performance (both in time and space) compared to binary archives.

JSON archives are only guaranteed to finish flushing their contents upon destruction and should thus be used in an RAII fashion.

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.

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.

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 **cereal::SizeTag** 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.

# [Constructor & Destructor Documentation](#Constructor_&_Destructor_Documentation)

## [cereal::JSONOutputArchive::JSONOutputArchive (std::ostream & stream, **Options** const & options = **Options::Default**()**)** \[inline\]](#cereal::JSONOutputArchive::JSONOutputArchive_%28std::ostream_&_stream,_)

Construct, outputting to the provided stream.

**Parameters**

*stream* The stream to output to.  
*options* The JSON specific options to use. See the **Options** struct for the values of default parameters

# [Member Function Documentation](#Member_Function_Documentation)

## [void cereal::JSONOutputArchive::saveBinaryValue (const void * data, size\_t size, const char * name = nullptr) \[inline\]](#void_cereal::JSONOutputArchive::saveBinaryValue_%28const_void_*_data,_size_t_size,_const_char_*_name_=_)

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

## [template&lt;class T, traits::EnableIf&lt; std::is\_arithmetic&lt; T &gt;::value, !std::is\_same&lt; T, long &gt;::value, !std::is\_same&lt; T, unsigned long &gt;::value, !std::is\_same&lt; T, std::int64\_t &gt;::value, !std::is\_same&lt; T, std::uint64\_t &gt;::value,(sizeof(T) &gt;=sizeof(long double)||sizeof(T) &gt;=sizeof(long long))&gt; = traits::sfinae&gt; void cereal::JSONOutputArchive::saveValue (T const & t) \[inline\]](#template_class_T,_traits::EnableIf__std::is_arithmetic__T__::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,%28sizeof%28T%29__=sizeof%28long_double%29__sizeof%28T%29__=sizeof%28long_long%29%29__=_traits::sfinae__void_cereal::JSONOutputArchive::saveValue_%28T_const_&_t%29)

Save exotic arithmetic as strings to current node. Handles long long (if distinct from other types), unsigned long (if distinct), and long double

## [void cereal::JSONOutputArchive::startNode () \[inline\]](#void_cereal::JSONOutputArchive::startNode_%28%29)

Starts a new node in the JSON output. The node can optionally be given a name by calling setNextName prior to creating the node

Nodes only need to be started for types that are themselves objects or arrays

## [void cereal::JSONOutputArchive::writeName () \[inline\]](#void_cereal::JSONOutputArchive::writeName_%28%29)

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.

The general workflow of saving to the JSON archive is:

1\.

(optional) Set the name for the next node to be created, usually done by an NVP

2\.

Start the node

3\.

(if there is data to save) Write the name of the node (this function)

4\.

(if there is data to save) Save the data (with saveValue)

5\.

Finish the node

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Sat Oct 10 2026 08:08:15 cereal

---

Document: cereal_JSONOutputArchive(3) from cereal 1.3.2-r6 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
