[#BloombergLP-baljsn-DatumUtil-encode-04] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/baljsn.adoc[baljsn]::xref:BloombergLP/baljsn/DatumUtil.adoc[DatumUtil]::encode :relfileprefix: ../../../ :mrdocs: Encode the specified `datum` as a JSON string onto the specified `stream`. == Synopsis Declared in `<baljsn_datumutil.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- static int encode( std::ostream& stream, xref:BloombergLP/bdld/Datum.adoc[bdld::Datum] const& datum); ---- == Description Return 0 on success, and a negative value if `datum` could not be encoded (which may leave a partial JSON sequence on the `stream`). If the optionally specified `options` argument is not present, treat it as a default‐constructed `DatumEncoderOptions`. If `options.strictTypes` is `true` and a type that is not supported by JSON, or a singular double value (e.g., NaN or infinity) is being encoded (see []Types)) return a positive value, but also populate `result` with an encoded JSON string (i.e., the value of `result` is the same regardless of the `strictTypes` option, but if `strictTypes` is `true` a non‐zero positive status will be returned). The mapping of types supported by `Datum` to JSON types is described in []Types). == Return Value 0 on success, a negative value on failure, or a positive value if `strictTypes` is enabled and an unsupported type is encoded == Parameters [cols="1,4"] |=== | Name| Description | *stream* | output stream for the encoded JSON | *datum* | `Datum` to encode |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#