|
BDE 4.14.0 Production release
|
Provide options for reading a JSON document.
This component provides a single, simply constrained (value-semantic) attribute class, bdljsn::ReadOptions, that is used to specify options for reading a JSON document (see bdljsn_jsonutil ).
maxNestedDepth: the maximum depth to which JSON objects and arrays are allowed to be nested before the JSON decoder reports an error. For example, if maxNestedDepth is 8, and a JSON text has 9 consecutive open brackets ([) then decoding will return an error. This option can be used to prevent poorly formed (or malicious) JSON text from causing a stack overflow.allowTrailingText: whether a read operation will report an error if any non-white space text follows a valid JSON document. By default this option is false, indicating the user expects the input to contain a single valid JSON document (without any subsequent text). When set to true a read operation will return success if there is text following a valid JSON document, assuming that text is separated by a delimeter. See bdljsn_jsonutil for details.This section illustrates intended use of this component.
This component is designed to be used at a higher level to set the options for decoding Datum objects in the JSON format. This example shows how to create and populate an options object.
First, we default-construct a bdljsn::ReadOptions object:
Finally, we populate that object to limit the maximum nested depth using a pre-defined limit: