[#BloombergLP-baljsn-DatumUtil-encode-03]
= 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 into the specified `result`&period;

== Synopsis

Declared in `&lt;baljsn&lowbar;datumutil&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
static
int
encode(
    xref:bsl/string.adoc[bsl::string]* result,
    xref:BloombergLP/bdld/Datum.adoc[bdld::Datum] const& datum);
----

== Description

Return 0 on success, and a negative value if `datum` could not be encoded (with no effect on `result`)&period; If the optionally specified `options` argument is not present, treat it as a default&hyphen;constructed `DatumEncoderOptions`&period; If `options&period;strictTypes` is `true` and a type that is not supported by JSON, or a singular double value (e&period;g&period;, NaN or infinity) is being encoded (see &lsqb;&rsqb;Types)) return a positive value, but also populate `result` with an encoded JSON string (i&period;e&period;, the value of `result` is the same regardless of the `strictTypes` option, but if `strictTypes` is `true` a non&hyphen;zero positive status will be returned)&period; The mapping of types supported by `Datum` to JSON types is described in &lsqb;&rsqb;Types)&period;

== 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
| *result*
| receives the encoded JSON string
| *datum*
| `Datum` to encode
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
