Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdljsn_writeoptions
[Package bdljsn]

Provide options for writing a JSON document. More...

Namespaces

namespace  bdljsn

Detailed Description

Outline
Purpose:
Provide options for writing a JSON document.
Classes:
bdljsn::WriteOptions options for writing a JSON document
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:
  const int  INITIAL_INDENT_LEVEL     = 1;
  const int  SPACES_PER_LEVEL         = 4;

  bdljsn::WriteOptions options;
  assert(0     == options.initialIndentLevel());
  assert(4     == options.spacesPerLevel());
  assert(false == options.sortMembers());
  assert(bdljsn::WriteStyle::e_COMPACT == options.style());
Finally, we populate that object using a pre-defined initial indent level and spaces per level:
  options.setInitialIndentLevel(INITIAL_INDENT_LEVEL);
  assert(INITIAL_INDENT_LEVEL == options.initialIndentLevel());

  options.setSpacesPerLevel(SPACES_PER_LEVEL);
  assert(SPACES_PER_LEVEL == options.spacesPerLevel());