[#BloombergLP-baljsn-Encoder-encode-09]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/baljsn.adoc[baljsn]::xref:BloombergLP/baljsn/Encoder.adoc[Encoder]::encode
:relfileprefix: ../../../
:mrdocs:

Encode `value` as JSON onto `stream` using `options`&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class TYPE&gt;
int
encode(
    std::ostream& stream,
    TYPE const& value,
    xref:BloombergLP/baljsn/EncoderOptions.adoc[EncoderOptions] const& options);
----

== Description

Encode the specified `value`, of (template parameter) `TYPE`, in the JSON format using the specified `options` and output it onto the specified `stream`&period; Specifying a nullptr `options` is equivalent to passing a default&hyphen;constructed EncoderOptions in `options`&period; `TYPE` shall be a `bdlat`&hyphen;compatible choice, or array type, or a `bdlat`&hyphen;compatible dynamic type referring to one of those types&period;

== Return Value

0 on success, and a non&hyphen;zero value otherwise

== Parameters

[cols="1,4"]
|===
| Name| Description
| *stream*
| output stream for JSON
| *value*
| value to encode
| *options*
| encoding options
|===


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