BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdljsn_writestyle

Detailed Description

Outline

Purpose

Enumerate the formatting styles for a writing a JSON document.

Classes

See also
bdljsn_writeoptions

Description

This component provides bdljsn::WriteStyle, a namespace for the enum type bdljsn::WriteStyle::Enum, which enumerates the set of format styles that can be used when writing a JSON document.

Enumerators

Name Description
------------- -------------------------------------------------------
e_PRETTY A human friendly format with configurable new lines and
indentation
e_ONELINE A single-line format with a space after each comma and
colon.
e_COMPACT A maximally compact format with no white space.

Usage

This section illustrates intended use of this component.

Example 1: Basic Syntax

The following snippets of code provide a simple illustration of using bdljsn::WriteStyle.

First, we create a variable value of type bdljsn::WriteStyle::Enum and initialize it with the enumerator value bdljsn::WriteStyle::e_PRETTY:

Enum
Definition bdljsn_writestyle.h:127
@ e_PRETTY
Definition bdljsn_writestyle.h:128

Now, we store the address of its ASCII representation in a pointer variable, asciiValue, of type const char *:

const char *asciiValue = bdljsn::WriteStyle::toAscii(value);
assert(0 == bsl::strcmp(asciiValue, "PRETTY"));
static const char * toAscii(WriteStyle::Enum value)

Finally, we print value to bsl::cout.

bsl::cout << value << bsl::endl;

This statement produces the following output on stdout:

PRETTY