BDE 4.14.0 Production release
|
Modules | |
bdljsn_error | |
Provide a description of an error processing a document. | |
bdljsn_json | |
Provide an in-memory representation of a JSON document. | |
bdljsn_jsonliterals | |
Provide user-defined literals for bdljsn::Json objects. | |
bdljsn_jsonnull | |
Provide a type that represents the JSON null value. | |
bdljsn_jsonnumber | |
Provide a value-semantic type representing a JSON number. | |
bdljsn_jsontestsuiteutil | |
Provide JSON Test Suite for BDE table-driven testing. | |
bdljsn_jsontype | |
Enumerate the set of JSON value types. | |
bdljsn_jsonutil | |
Provide common non-primitive operations on Json objects. | |
bdljsn_location | |
Provide a value-semantic type for location in a JSON document. | |
bdljsn_numberutil | |
Provide utilities converting between JSON text and numeric types. | |
bdljsn_readoptions | |
Provide options for reading a JSON document. | |
bdljsn_stringutil | |
Provide a utility functions for JSON strings. | |
bdljsn_tokenizer | |
Provide a tokenizer for extracting JSON data from a streambuf . | |
bdljsn_writeoptions | |
Provide options for writing a JSON document. | |
bdljsn_writestyle | |
Enumerate the formatting styles for a writing a JSON document. | |
Provide a value-semantic JSON type and supporting utilities
Basic Development Library JSoN (bdljsn)
The 'bdljsn' package provides the 'bdljsn::Json' type, found in the bdljsn_json component, which is a value-semantic representation of JSON data. This package also provides facilities for reading and writing 'bdljsn::Json' objects to JSON documents. 'bdljsn::Json' has close structural similarities to the JSON grammar itself, which looks like the following, at a high level:
Noting that the 'Object' and 'Array' alternatives can recursively contain 'JSON'. Just like this grammar, the value of a 'bdljsn::Json' object can be an object, array, string, number, boolean, or the null value. Objects and Arrays are represented by the 'bdljsn::JsonObject' and 'bdljsn::JsonArray' types, respectively, and are also provided by the bdljsn_json component. 'bdljsn::JsonObject' is an associative container from strings to 'bdljsn::Json' objects, and 'bdljsn::JsonArray' is a sequence container with 'bdljsn::Json' elements. Strings and booleans are represented with the standard 'bsl::string' and 'bool' types. The singular "null" value is represented by the 'bdljsn::JsonNull' type, which has a single value like 'std::monostate'. Numbers are represented by the 'bdljsn::JsonNumber' type, which has facilities for storing any number that satisfies the JSON number grammar with arbitrary precision. It also provides operations for converting these arbitrary-precision numbers to common finite-precision number vocabulary types like 'int', 'double', and 'bdldfp::Decimal64', and detecting where overflow, underflow, and/or truncation would occur during conversion.
Though this package provides several types representing different kinds of JSON values, in general the 'bdljsn::Json' interface is rich enough to be the primary vocabulary type for working with JSON. For example, if the value stored in a 'bdljsn::Json' holds a JSON object, then you can use much of the associative container interface on the 'bdljsn::Json' object directly, e.g.,
Alternatively, if a 'bdljsn::Json' holds a JSON array, then we can use it like a sequence container,
For an example of constructing 'bdljsn::Json' objects, consider the use case where we have a simple representation of an organization chart, which we would like to convert to JSON for printing to standard output:
We can define utility functions for converting these types to JSON:
And then we can create a sample 'Team' and print it to standard output using our 'toJson' functions,
Then, we can observe the following printed to standard output:
The 'bdljsn' package currently has 15 components having 5 levels of physical dependency. The list below shows the hierarchical ordering of the components. The order of components within each level is not architecturally significant, just alphabetical.
bdljsn_error : Provide a description of an error processing a document.
bdljsn_json : Provide an in-memory representation of a JSON document.
bdljsn_jsonliterals : Provide user-defined literals for bdljsn::Json
objects.
bdljsn_jsonnull : Provide a type that represents the JSON null
value.
bdljsn_jsonnumber : Provide a value-semantic type representing a JSON number.
bdljsn_jsontestsuiteutil : Provide JSON Test Suite for BDE table-driven testing.
bdljsn_jsontype : Enumerate the set of JSON value types.
bdljsn_jsonutil : Provide common non-primitive operations on Json
objects.
bdljsn_location : Provide a value-semantic type for location in a JSON document.
bdljsn_numberutil : Provide utilities converting between JSON text and numeric types.
bdljsn_readoptions : Provide options for reading a JSON document.
bdljsn_stringutil : Provide a utility functions for JSON strings.
bdljsn_tokenizer : Provide a tokenizer for extracting JSON data from a streambuf
.
bdljsn_writeoptions : Provide options for writing a JSON document.
bdljsn_writestyle : Enumerate the formatting styles for a writing a JSON document.