Provide options for writing a JSON document.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide options for writing a JSON document.
-
- Classes:
-
- See also:
- Component bdljsn_jsonutil, Component bdljsn_json
-
- Description:
- This component provides a single, simply constrained (value-semantic) attribute class,
bdljsn::WriteOptions
, that is used to specify options for writing a JSON document (see bdljsn_jsonutil
).
-
- Attributes:
Name Type Default Simple Constraints
------------------ ----------- ------- ------------------
initialIndentLevel int 0 >= 0
sortMembers bool false none
spacesPerLevel int 4 >= 0
style WriteStyle e_COMPACT none
-
initialIndentLevel
: initial indent level for the top-most element. If style
is e_COMPACT
, or spacesPerLevel
is 0, this option is ignored.
-
sortMembers
: indicates whether the members of a object will be sorted in lexicographical order based on the member name.
-
spacesPerLevel
: spaces per indent level. If this option is 0, no indentation is used. If style
is e_COMPACT
or e_ONELINE
, this option is ignored.
-
style
: the style used to encode the JSON data.
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Creating and Populating an Options Object:
- This component is designed to be used at a higher level to set the options for writing
bdljsn::Json
objects in JSON format. This example shows how to create and populate an options object.
- First, we default-construct a
bdljsn::WriteOptions
object: Finally, we populate that object using a pre-defined initial indent level and spaces per level: