class new in Git master
#include <Corrade/Utility/Json.h>
Json JSON parser.
Tokenizes a JSON file together with optional parsing of selected token subtrees. Supports files over 4 GB and parsing of numeric values into 32-bit floating-point, 32-bit and 52-/53-bit unsigned and signed integer types in addition to the general 64-bit floating-point representation.
To optimize for parsing performance and minimal memory usage, the parsed tokens are contained in a single contiguous allocation and form an immutable view on the input JSON string. As the intended usage is sequential processing of chosen parts of the file, there's no time spent building any acceleration structures for fast lookup of keys and array indices — if that's desired, users are encouraged to build them on top of the parsed output.
The JsonWriter class provides a write-only counterpart for saving a JSON file.
Usage
The following snippet opens a very minimal glTF file, parses it including unescaping strings and converting numbers to floats, and accesses the known properties:
{ "asset": { "version": "2.0" }, "nodes": [ …, { "name": "Fox", "mesh": 5 } ] }
Containers::Optional<Utility::Json> gltf = Utility::Json::fromFile("scene.gltf", Utility::Json::Option::ParseLiterals| Utility::Json::Option::ParseFloats| Utility::Json::Option::ParseStrings); if(!gltf) Utility::Fatal{} << "Whoops!"; const Utility::JsonToken& gltfNode = gltf->root()["nodes"][i]; Utility::Debug{} << "Node" << i << "is named" << gltfNode["name"].asString() << "and has a mesh" << gltfNode["mesh"].asFloat();
The above — apart from handling a parsing failure — assumes that the node i
we're looking for exists in the file and contains the properties we want. But that might not always be the case and so it could assert if we'd ask for something that's not there. This is how it would look with JsonToken::
const Utility::JsonToken *gltfNodes, *gltfNode; if(!(gltfNodes = gltf->root().find("nodes")) || !(gltfNode = gltfNodes->find(i))) Utility::Fatal{} << "Node" << i << "is not in the file"; if(const Utility::JsonToken* gltfName = gltfNode->find("name")) Utility::Debug{} << "Node" << i << "is named" << gltfName->asString(); if(const Utility::JsonToken* gltfMesh = gltfNode->find("mesh")) Utility::Debug{} << "Node" << i << "has a mesh" << gltfMesh->asFloat();
Selective parsing
As shown above, the Option values passed to fromFile() or fromString() cause the file to get fully parsed upfront including number conversion and string unescaping. While that's a convenient behavior that makes sense when consuming the whole file, doing all that might be unnecessary when you only need to access a small portion of a large file. In the following snippet, all literals and string keys get parsed upfront so objects and arrays can be searched, but then we parse only contents of the particular node using parseStrings() and parseFloats():
Containers::Optional<Utility::Json> gltf = Utility::Json::fromFile("scene.gltf", Utility::Json::Option::ParseLiterals| Utility::Json::Option::ParseStringKeys); const Utility::JsonToken* gltfNode = …; if(!gltfNode || !gltf->parseStrings(*gltfNode) || !gltf->parseFloats(*gltfNode)) Utility::Fatal{} << "Invalid node" << i;
This way we also have a greater control over parsed numeric types. Instead of parsing everything as a float using Option::
if(const Utility::JsonToken* gltfMesh = gltfNode->find("mesh")) { if(!gltf->parseUnsignedInts(*gltfMesh)) Utility::Fatal{} << "Invalid node" << i << "mesh reference"; Utility::Debug{} << "Node" << i << "has a mesh" << gltfMesh->asUnsignedInt(); }
Finally, while a JSON number is defined to be of a double
type, often the full precision is not needed and so we parsed everything as floats. If the precision indeed is important, you can switch to Option::
Checked selective parsing
At this point, the code can handle variations in valid glTF files, but isn't immune from files that don't follow the spec — for example where the root element is not an object, or a name isn't a string. Those would still cause the find()
and as*()
APIs to assert.
If we omit all Parse*
Options in fromString() / fromFile(), the instance will behave as if nothing was parsed yet. Thus any call to JsonToken::
Containers::Optional<Utility::Json> gltf = Utility::Json::fromFile("scene.gltf"); if(!gltf->parseObject(gltf->root())) Utility::Fatal{} << "Can't parse glTF root"; const Utility::JsonToken* gltfNodes = gltf->root().find("nodes"); if(!gltfNodes || !gltf->parseArray(*gltfNodes)) Utility::Fatal{} << "Missing or invalid nodes array"; const Utility::JsonToken* gltfNode = gltfNodes->find(i); if(!gltfNode || !gltf->parseObject(*gltfNode)) Utility::Fatal{} << "Missing or invalid node" << i; if(const Utility::JsonToken* gltfName = gltfNode->find("name")) { if(Containers::Optional<Containers::StringView> s = gltf->parseString(*gltfName)) Utility::Debug{} << "Node" << i << "is named" << *s; else Utility::Fatal{} << "Invalid node" << i << "name"; } if(const Utility::JsonToken* gltfMesh = gltfNode->find("mesh")) { if(Containers::Optional<unsigned> n = gltf->parseUnsignedInt(*gltfMesh)) Utility::Debug{} << "Node" << i << "has a mesh" << *n; else Utility::Fatal{} << "Invalid node" << i << "mesh reference"; }
A possibly non-obvious side-effect of using various parse*()
APIs instead of checking JsonToken::
Iterating objects and arrays
So far, we only accessed object and array elements by a concrete key or an index. Because the internal representation is optimized for linear consumption rather than lookup by keys or values, those are operations. If the whole file is being consumed, a more efficient way may be iterating over object and array contents using JsonToken::
struct Node { Containers::StringView name; unsigned mesh; }; Containers::Array<Node> nodes; for(Utility::JsonArrayItem gltfNode: gltfNodes->asArray()) { Utility::Debug{} << "Parsing node" << gltfNode.index(); Node node; for(Utility::JsonObjectItem gltfNodeProperty: gltfNode.value().asObject()) { if(gltfNodeProperty.key() == "name") node.name = gltfNodeProperty.value().asString(); else if(gltfNodeProperty.key() == "mesh") node.mesh = gltfNodeProperty.value().asFloat(); … } arrayAppend(nodes, node); }
Both JsonObjectItem and JsonArrayItem is implicitly convertible to a JsonToken reference, giving back either the object key (of which the value is JsonToken::
Containers::Array<Containers::Reference<const Utility::JsonToken>> gltfNodeMap; for(const Utility::JsonToken& gltfNode: gltfNodes->asArray()) arrayAppend(gltfNodeMap, gltfNode);
Direct access to arrays
Besides high-level array iteration, there's also a set of functions for accessing homogeneous arrays. Coming back to the glTF format, for example a node translation vector and child indices:
{ "translation": [1.5, -0.5, 2.3], "children": [2, 3, 4, 17, 399] }
We'll check, parse and access the first property with parseFloatArray() and the other with parseUnsignedIntArray() — those will check that it's indeed an array and that it contains either all floats or all unsigned integers. If everything passes, we get back a Containers::
Containers::Optional<Containers::StridedArrayView1D<const float>> translation; if(const Utility::JsonToken* gltfNodeTranslation = gltfNode.find("translation")) if(!(translation = gltf->parseFloatArray(*gltfNodeTranslation, 3))) Utility::Fatal{} << "Node translation is not a 3-component float vector"; Containers::Optional<Containers::StridedArrayView1D<const unsigned>> children; if(const Utility::JsonToken* gltfNodeChildren = gltfNode.find("children")) if(!(children = gltf->parseUnsignedIntArray(*gltfNodeChildren))) Utility::Fatal{} << "Node children is not an index list"; // use the translation and children arrays …
This feature isn't limited to just numeric arrays — for booleans there's parseBitArray() returning a Containers::
Tokenization and parsing process
The class expects exactly one top-level JSON value, be it an object, array, literal, number or a string.
The tokenization process is largely inspired by jsmn — the file gets processed to a flat list of JsonToken instances, where each literal, number, string (or a string object key), object and array is one token, ordered in a depth-first manner. Whitespace is skipped and not present in the parsed token list. JsonToken::
This allows the application to reduce the initial processing time and memory footprint. Token parsing is a subsequent step, parsing the string range of a token as a literal, converting it to a number or interpreting string escape sequences. This step can then fail on its own, for example when an invalid literal value is encountered, when a Unicode escape is out of range or when a parsed integer doesn't fit into the output type size.
Token hierarchy is defined as the following — object tokens have string keys as children, string keys have object values as children, arrays have array values as children and values themselves have no children. As implied by the depth-first ordering, the first child token (if any) is ordered right after its parent token, and together with JsonToken::
Internal representation
If the string passed to fromString() is Containers::
A JsonToken is 16 bytes on 32-bit systems and 24 bytes on 64-bit systems, containing view pointer, size and child count. When a literal or numeric value is parsed, it's stored inside. Simply put, the representation exploits the fact that a token either has children or is a value, but never both. For strings the general assumption is that most of them (and especially object keys) don't contain any escape characters and thus can be returned as views on the input string. Strings containing escape characters are allocated separately, either upfront if Option::
Public types
- enum class Option { ParseLiterals = 1 << 0, ParseDoubles = 1 << 1, ParseFloats = 1 << 2, ParseStringKeys = 1 << 3, ParseStrings = ParseStringKeys|(1 << 4) }
- Parsing option.
-
using Options = Containers::
EnumSet<Option> - Parsing options.
Public static functions
-
static auto fromString(Containers::
StringView string, Options options = {}, Containers:: StringView filename = {}, std:: size_t lineOffset = 0, std:: size_t columnOffset = 0) -> Containers:: Optional<Json> - Parse a JSON string.
-
static auto fromString(Containers::
StringView string, Containers:: StringView filename, std:: size_t lineOffset = 0, std:: size_t columnOffset = 0) -> Containers:: Optional<Json> -
static auto fromFile(Containers::
StringView filename, Options options = {}) -> Containers:: Optional<Json> - Parse a JSON file.
Constructors, destructors, conversion operators
Public functions
- auto operator=(const Json&) -> Json& deleted
- Copying is not allowed.
- auto operator=(Json&&) -> Json& noexcept
- Move assignment.
-
auto tokens() const -> Containers::
ArrayView<const JsonToken> - Parsed JSON tokens.
- auto root() const -> const JsonToken&
- Root JSON token.
- auto parseLiterals(const JsonToken& token) -> bool
- Parse objects, arrays,
null
,true
andfalse
values in given token tree. - auto parseDoubles(const JsonToken& token) -> bool
- Parse numbers in given token tree as 64-bit floating-point values.
- auto parseFloats(const JsonToken& token) -> bool
- Parse numbers in given token tree as 32-bit floating-point values.
- auto parseUnsignedInts(const JsonToken& token) -> bool
- Parse numbers in given token tree as unsigned 32-bit integer values.
- auto parseInts(const JsonToken& token) -> bool
- Parse numbers in given token tree as signed 32-bit integer values.
- auto parseUnsignedLongs(const JsonToken& token) -> bool
- Parse numbers in given token tree as unsigned 52-bit integer values.
- auto parseLongs(const JsonToken& token) -> bool
- Parse numbers in given token tree as signed 53-bit integer values.
- auto parseSizes(const JsonToken& token) -> bool
- Parse numbers in given token tree as size values.
- auto parseStringKeys(const JsonToken& token) -> bool
- Parse string keys in given token tree.
- auto parseStrings(const JsonToken& token) -> bool
- Parse strings in given token tree.
-
auto parseObject(const JsonToken& token) -> Containers::
Optional<JsonObjectView> - Check and parse an object token.
-
auto parseArray(const JsonToken& token) -> Containers::
Optional<JsonArrayView> - Check and parse an array token.
-
auto parseNull(const JsonToken& token) -> Containers::
Optional<std:: nullptr_t> - Check and parse a null token.
-
auto parseBool(const JsonToken& token) -> Containers::
Optional<bool> - Check and parse a boolean token.
-
auto parseDouble(const JsonToken& token) -> Containers::
Optional<double> - Check and parse a 64-bit floating-point token.
-
auto parseFloat(const JsonToken& token) -> Containers::
Optional<float> - Check and parse a 32-bit floating-point token.
-
auto parseUnsignedInt(const JsonToken& token) -> Containers::
Optional<std:: uint32_t> - Check and parse an unsigned 32-bit integer token.
-
auto parseInt(const JsonToken& token) -> Containers::
Optional<std:: int32_t> - Check and parse a signed 32-bit integer token.
-
auto parseUnsignedLong(const JsonToken& token) -> Containers::
Optional<std:: uint64_t> - Check and parse an unsigned 52-bit integer token.
-
auto parseLong(const JsonToken& token) -> Containers::
Optional<std:: int64_t> - Check and parse a signed 53-bit integer token.
-
auto parseSize(const JsonToken& token) -> Containers::
Optional<std:: size_t> - Check and parse a size token.
-
auto parseString(const JsonToken& token) -> Containers::
Optional<Containers:: StringView> - Check and parse a string token.
-
auto parseBitArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedBitArrayView1D> - Check and parse a bit array.
-
auto parseBoolArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const bool>> deprecated in Git master - Check and parse a boolean array.
-
auto parseDoubleArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const double>> - Check and parse a 64-bit floating-point array.
-
auto parseFloatArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const float>> - Check and parse a 32-bit floating-point array.
-
auto parseUnsignedIntArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const std:: uint32_t>> - Check and parse an unsigned 32-bit integer array.
-
auto parseIntArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const std:: int32_t>> - Check and parse a signed 32-bit integer array.
-
auto parseUnsignedLongArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const std:: uint64_t>> - Check and parse an unsigned 52-bit integer array.
-
auto parseLongArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const std:: int64_t>> - Check and parse a signed 52-bit integer array.
-
auto parseSizeArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StridedArrayView1D<const std:: size_t>> - Check and parse a size array.
-
auto parseStringArray(const JsonToken& token,
std::
size_t expectedSize = 0) -> Containers:: Optional<Containers:: StringIterable> - Check and parse a string array.
Enum documentation
enum class Corrade:: Utility:: Json:: Option
Parsing option.
Enumerators | |
---|---|
ParseLiterals |
Parse objects, arrays, Invalid values will cause fromString() / fromFile() to print an error and return Containers:: Note that using JsonToken:: |
ParseDoubles |
Parse all numbers as 64-bit floating-point values. Causes all JsonToken instances of JsonToken:: Invalid values will cause fromString() / fromFile() to exit with a parse error. This operation can be also performed selectively later using parseDoubles(), or directly for particular tokens using parseDouble(). While this option is guaranteed to preserve the full precision of JSON numeric literals, often you may need only 32-bit precision — use Option:: |
ParseFloats |
Parse all numbers as 32-bit floating-point values. Causes all JsonToken instances of JsonToken:: Invalid values will cause fromString() / fromFile() to exit with a parse error. This operation can be also performed selectively later using parseFloats(), or directly for particular tokens using parseFloat(). While 32-bit float precision is often enough, sometimes you might want to preserve the full precision of JSON numeric literals — use Option:: |
ParseStringKeys |
Parse object key strings by processing all escape sequences and caching the parsed result (or marking the original string as parsed in-place, if it has no escape sequences). Causes JsonToken instances of JsonToken:: Invalid values will cause fromString() / fromFile() to exit with a parse error. This operation can be also performed selectively later using parseStringKeys(), or directly for particular tokens using parseString(). |
ParseStrings |
Parse string values by processing all escape sequences and caching the parsed result (or marking the original string as parsed in-place, if it has no escape sequences). Causes all JsonToken instances of JsonToken:: Invalid values will cause fromString() / fromFile() to exit with a parse error. This operation can be also performed selectively later using parseStrings(), or directly for particular tokens using parseString(). |
Typedef documentation
typedef Containers:: EnumSet<Option> Corrade:: Utility:: Json:: Options
Parsing options.
Function documentation
static Containers:: Optional<Json> Corrade:: Utility:: Json:: fromString(Containers:: StringView string,
Options options = {},
Containers:: StringView filename = {},
std:: size_t lineOffset = 0,
std:: size_t columnOffset = 0)
Parse a JSON string.
Parameters | |
---|---|
string | JSON string to parse |
options | Parsing options |
filename | Filename to use for error reporting. If not set, <in> is printed in error messages. |
lineOffset | Initial line offset in the file for error reporting |
columnOffset | Initial column offset in the file for error reporting |
By default performs only tokenization, not parsing any literals. Use options
to enable parsing of particular token types as well. If a tokenization or parsing error happens, prints a message to Error and returns Containers::
If the string
is Containers::
The filename
, lineOffset
and columnOffset
parameters have no effect on actual parsing and are used only to enhance error messages. Line offset is added to the reported line always but column offset is used only if the happens on the first line of the JSON string, errors on subsequent lines are reported without the initial column offset.
static Containers:: Optional<Json> Corrade:: Utility:: Json:: fromString(Containers:: StringView string,
Containers:: StringView filename,
std:: size_t lineOffset = 0,
std:: size_t columnOffset = 0)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
static Containers:: Optional<Json> Corrade:: Utility:: Json:: fromFile(Containers:: StringView filename,
Options options = {})
Parse a JSON file.
By default performs only tokenization, not parsing any literals. Use options
to enable parsing of particular token types as well. If the file can't be read, or a tokenization or parsing error happens, prints a message to Error and returns Containers::
Containers:: ArrayView<const JsonToken> Corrade:: Utility:: Json:: tokens() const
Parsed JSON tokens.
The first token is the root token (also accessible via root()) and is always present, the rest is ordered in a depth-first manner as described in Tokenization and parsing process.
const JsonToken& Corrade:: Utility:: Json:: root() const
Root JSON token.
Always present. Tts JsonToken::
bool Corrade:: Utility:: Json:: parseLiterals(const JsonToken& token)
Parse objects, arrays, null
, true
and false
values in given token tree.
Causes all JsonToken instances of JsonToken::false
. Expects that token
references a token owned by this instance.
Passing root() as token
has the same effect as Option::
Note that using JsonToken::
bool Corrade:: Utility:: Json:: parseDoubles(const JsonToken& token)
Parse numbers in given token tree as 64-bit floating-point values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Passing root() as token
has the same effect as Option::
bool Corrade:: Utility:: Json:: parseFloats(const JsonToken& token)
Parse numbers in given token tree as 32-bit floating-point values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Passing root() as token
has the same effect as Option::
bool Corrade:: Utility:: Json:: parseUnsignedInts(const JsonToken& token)
Parse numbers in given token tree as unsigned 32-bit integer values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Checking a single token for a numeric type and parsing it as an unsigned int can be done using parseUnsignedInt().
bool Corrade:: Utility:: Json:: parseInts(const JsonToken& token)
Parse numbers in given token tree as signed 32-bit integer values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Checking a single token for a numeric type and parsing it as an int can be done using parseUnsignedInt().
bool Corrade:: Utility:: Json:: parseUnsignedLongs(const JsonToken& token)
Parse numbers in given token tree as unsigned 52-bit integer values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Checking a single token for a numeric type and parsing it as an unsigned long can be done using parseUnsignedInt().
bool Corrade:: Utility:: Json:: parseLongs(const JsonToken& token)
Parse numbers in given token tree as signed 53-bit integer values.
Causes all JsonToken instances of JsonToken::token
and its children to become JsonToken::false
. Expects that token
references a token owned by this instance.
Checking a single token for a numeric type and parsing it as a long can be done using parseLong().
bool Corrade:: Utility:: Json:: parseSizes(const JsonToken& token)
Parse numbers in given token tree as size values.
Convenience function that calls into parseUnsignedInts() on 32-bit targets and into parseUnsignedLongs() on 64-bit. Besides being available under the concrete types as documented in these functions, JsonToken instances of JsonToken::token
and its children will alias to JsonToken::
Checking a single token for a numeric type and parsing it as a size can be done using parseSize().
bool Corrade:: Utility:: Json:: parseStringKeys(const JsonToken& token)
Parse string keys in given token tree.
Causes all JsonToken instances of JsonToken::token
and its children to have JsonToken::false
. Expects that token
references a token owned by this instance.
Passing root() as token
has the same effect as Option::
bool Corrade:: Utility:: Json:: parseStrings(const JsonToken& token)
Parse strings in given token tree.
Causes all JsonToken instances of JsonToken::token
and its children to have JsonToken::false
. Expects that token
references a token owned by this instance.
Passing root() as token
has the same effect as Option::
Containers:: Optional<JsonObjectView> Corrade:: Utility:: Json:: parseObject(const JsonToken& token)
Check and parse an object token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<JsonArrayView> Corrade:: Utility:: Json:: parseArray(const JsonToken& token)
Check and parse an array token.
If token
is not a JsonToken::false
. If JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: nullptr_t> Corrade:: Utility:: Json:: parseNull(const JsonToken& token)
Check and parse a null token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<bool> Corrade:: Utility:: Json:: parseBool(const JsonToken& token)
Check and parse a boolean token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<double> Corrade:: Utility:: Json:: parseDouble(const JsonToken& token)
Check and parse a 64-bit floating-point token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<float> Corrade:: Utility:: Json:: parseFloat(const JsonToken& token)
Check and parse a 32-bit floating-point token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: uint32_t> Corrade:: Utility:: Json:: parseUnsignedInt(const JsonToken& token)
Check and parse an unsigned 32-bit integer token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: int32_t> Corrade:: Utility:: Json:: parseInt(const JsonToken& token)
Check and parse a signed 32-bit integer token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: uint64_t> Corrade:: Utility:: Json:: parseUnsignedLong(const JsonToken& token)
Check and parse an unsigned 52-bit integer token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: int64_t> Corrade:: Utility:: Json:: parseLong(const JsonToken& token)
Check and parse a signed 53-bit integer token.
If token
is not a JsonToken::token
references a token owned by this instance.
Containers:: Optional<std:: size_t> Corrade:: Utility:: Json:: parseSize(const JsonToken& token)
Check and parse a size token.
Convenience function that calls into parseUnsignedInt() on 32-bit targets and into parseUnsignedLong() on 64-bit. If the token is already parsed as JsonToken::token
references a token owned by this instance.
Containers:: Optional<Containers:: StringView> Corrade:: Utility:: Json:: parseString(const JsonToken& token)
Check and parse a string token.
If token
is not a JsonToken::token
references a token owned by this instance. If fromString() was called with a global literal and the string didn't contain any escape sequences, the returned view has Containers::
Containers:: Optional<Containers:: StridedBitArrayView1D> Corrade:: Utility:: Json:: parseBitArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a bit array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const bool>> Corrade:: Utility:: Json:: parseBoolArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a boolean array.
Containers:: Optional<Containers:: StridedArrayView1D<const double>> Corrade:: Utility:: Json:: parseDoubleArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a 64-bit floating-point array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const float>> Corrade:: Utility:: Json:: parseFloatArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a 32-bit floating-point array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const std:: uint32_t>> Corrade:: Utility:: Json:: parseUnsignedIntArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse an unsigned 32-bit integer array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const std:: int32_t>> Corrade:: Utility:: Json:: parseIntArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a signed 32-bit integer array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const std:: uint64_t>> Corrade:: Utility:: Json:: parseUnsignedLongArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse an unsigned 52-bit integer array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const std:: int64_t>> Corrade:: Utility:: Json:: parseLongArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a signed 52-bit integer array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance, the returned view points to data owned by this instance.
Containers:: Optional<Containers:: StridedArrayView1D<const std:: size_t>> Corrade:: Utility:: Json:: parseSizeArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a size array.
Convenience function that calls into parseUnsignedIntArray() on 32-bit targets and into parseUnsignedLongArray() on 64-bit.
Containers:: Optional<Containers:: StringIterable> Corrade:: Utility:: Json:: parseStringArray(const JsonToken& token,
std:: size_t expectedSize = 0)
Check and parse a string array.
If token
is not a JsonToken::expectedSize
is not 0
and the array has different size, prints a message to Error and returns Containers::token
references a token owned by this instance. If fromString() was called with a global literal and the string didn't contain any escape sequences, the returned views have Containers::