Skip to content

JSON

Generated from engine/assets/json.h at 862e08b. The text under each declaration is the header's own comment, word for word. About the reference says how these pages are made.

Browse the assets module

#include "engine/assets/json.h" · namespace labrador

JsonDocument read_json_file(const char* path);

Reads the UTF-8 file path in full and parses it as JSON.

Throws std::runtime_error naming the path if the file cannot be opened, cannot be read, or does not parse. The returned document is therefore always valid - callers never have to test for a parse error.

class JsonValue

A borrowed view of one node inside a JsonDocument.

Every accessor checks two things and throws naming the file, the position in it and the key when either fails: that this node is the kind the accessor needs, and that what it asks for is present and of the right type. rapidjson's own accessors assert instead, and NDEBUG disarms the assert - so a hand-edited content file that a debug build catches with a dialog box is a null dereference in a Release build. Content files are the one input a person types by hand, so every read of one is checked (T6).

This is a pointer, not a copy: it is valid only while the document it came from is alive.

JsonValue object(const char* key) const;
JsonValue array(const char* key) const;
std::string string(const char* key) const;

Required members of an object.

identifier · integer · number · boolean

Section titled “identifier · integer · number · boolean”
std::string identifier(const char* key) const;
int integer(const char* key) const;
float number(const char* key) const;
bool boolean(const char* key) const;

Identifier/path strings cannot contain NULs; errors name the field.

bool has(const char* key) const;

True if key is present, whatever its type. The one door to a field a file is allowed to leave out.

size_t size() const;
JsonValue at(size_t index) const;

Arrays. Both throw unless this node is one.

std::string as_string() const;
std::string as_identifier() const;

This node read as a scalar, for array elements, which have no key.

std::string where() const;

Where this node is, as './manifest.json': assets[1], for a caller with its own reason to reject what it read. An unknown colour name or object type is a content mistake exactly like a missing key, and it deserves the same sentence pointing at it (T6).

A parsed JSON file, and the owner of every JsonValue taken out of it.

Move-only: a document is a parse of a file, and copying one would copy the arena it parsed into.

~JsonDocument · JsonDocument · operator=

Section titled “~JsonDocument · JsonDocument · operator=”
JsonDocument(JsonDocument&&) noexcept;
JsonDocument& operator=(JsonDocument&&) noexcept;
JsonValue root() const;

The top of the file. Its own type is not checked here - the first accessor used on it is what says which type it needed and did not get.

const std::string& source_path() const;

The path this was read from, as it was given to read_json_file.

The files that include this header directly. A file can also reach it through another header.

Development documentation (unreleased). Built from Labrador 862e08b of 2026-10-08.