Flecs v3.2
A fast entity component system (ECS) for C & C++
|
This document provides an overview of the JSON serializer format. For an overview of how to use the JSON serializer API, see the JSON addon documentation.
This section describes value kinds that are used by the JSON serializers.
A name field returns the name of an entity as returned by ecs_get_name
or flecs::entity::name
.
Example:
A path field returns the path identifier of an entity as returned by ecs_get_fullpath
or flecs::entity::path
. The path contains the entity's name and the names of its parent and grandparents separated by a dot (.
).
Example:
A label field returns the doc name of the entity as returned by ecs_doc_get_name
or flecs::entity::doc_name
. The doc name is a user-friendly name for the entity that does not need to be unique and may contain any character.
Serializing labels requires the doc addon.
Example:
An id field returns a component id or pair. It is formatted as an array of at least one and at most three elements where the elements have the following meaning:
Each element is formatted as a Path.
Example:
Same as Id but with Label's instead of paths.
Example:
A JSON object or scalar representing the value of a component. Component values can only be serialized if the component is described in the reflection framework (see the meta addon).
When a component has no value (e.g. a tag) or is not described by the reflection framework, 0
will be used as placeholder.
Example:
A JSON object that represents the structure of a component type.
Example:
The entity kind is an object that contains metadata and data of a single serialized entity, and is returned by the Entity serializer.
The following sections describe the fields that an object of the entity kind may contain:
The entity path.
Type: Path, optional
The entity doc name.
Type: Label, optional
Brief description (as returned by ecs_doc_get_brief
).
Type: string, optional
Link to URL (as returned by ecs_doc_get_link
).
Type: string, optional
Base entities.
Type: Array(Entity), optional
Component ids.
Type: Array(Id)
Component labels.
Type: Array(Id label), optional
Array indicating whether a component is hidden. Only applies to components of base entities (in the ["is_a"](is_a) array).
A base component is hidden when it is overridden by an entity higher in the inheritance hierarchy.
Type: Array(bool), optional
Component values.
Type: Array(Value), optional
Array with objects that describe the component types of the terms.
Type: Array(Type info), optional
Default serializer options:
This example shows an entity with a base (an IsA
relationship) with default serializer options:
This example shows an entity with a base with all serializer options enabled:
The result kind is an object that contains the metadata and data of a single result returned by an iterator (see Iterator).
The following sections describe the fields that an object of the entity kind may contain:
Parent of the entity in current result.
Type: Array(Path), optional
Array with paths of the returned entities.
Type: Array(Name), optional
Same as entities, but with Label's instead of paths.
Type: Array(Label), optional
Same as entities, but with numerical ids instead of paths.
Type: Array(Number), optional
Array with paths of sources for each term. A subject indicates the actual entity on which a component is stored. If this is the matched entity (default) the array will contain a 0
element.
Type: Array(Path), optional
Array with variable values for current result (see query variables).
Type: Array(Path), optional
Same as variables, but with Label's instead of paths.
Type: Array(Label), optional
Same as variables, but with numerical ids instead of paths.
Type: Array(Number), optional
Array with component ids. This list is more specific than the ids array provided by the top-level iterator object. The arrays can be different in the case of terms with an Or
operator, or terms with wildcard ids.
Type: Array(string), optional
Array with booleans that can be used to determine whether terms with the Optional
operator are set.
Type: Array(bool), optional
Array with component values. The array contains an element for each term. If a component has no value, or no value could be serialized for the component a []
element is added.
Each element in the array can be either an array with component values when the component is from the matched entity, or a single component value when the component is from another entity (like a parent, prefab, singleton).
Type: Array(Array(Value)), optional
The iterator kind is an object that contains metadata and data of all the entities yielded by an iterator.
Array with ids for each term.
Type: Array(string), optional
Array with variable names (see query variables).
Type: Array(string), optional
Array with elements for each returned result.
Type: Array(Result)
Time it took to serialize the iterator.
Type: Number
Array with objects that describe the component types of the terms.
Type: Array(Type info), optional
The entity serializer returns a JSON string of the Entity type. This format is returned by ecs_entity_to_json
and flecs::entity::to_json
.
The following options (found in ecs_entity_to_json_desc_t
) customize the output of the entity serializer:
Serialize the "path" member.
Default: true
Example:
Serialize the "label" member.
Default: false
Example:
Serialize the "brief" member.
Default: false
Example:
Serialize the "link" member.
Default: false
Example:
Serializes the "id_labels" member.
Default: false
Example:
Serializes the "is_a" member.
Default: true
Example:
Serialize private components. Private components are regular components with the EcsPrivate
(or flecs::Private
) tag. When serialize_private
is false, private components will be hidden from all arrays.
Example:
Default: false
Serializes the "hidden" member.
Example:
Full example:
Note that hidden[0]
is true
in this example, because the Position
component from planets.RockyPlanet
is overridden by the entity.
Default: false
Serializes the "values" member.
Example:
Default: false
Serialize the "type_info" member.
Example:
The entity serializer returns a JSON string of the Iterator type. This format is returned by ecs_iter_to_json
.
Serialize the top level "ids" member.
Default: true
Example:
Example result for query Position, Jedi
Serialize the result specific "ids" member.
If the iterated query does not contain variable ids (either an Or
term or a term with a wildcard id) the result specific ids
member will exactly match the top-level ids
member.
Default: true
Example:
Example result for query Position, (Likes, *)
Serialize the "sources" member.
Default: true
Example:
Example result for query Position, Position(parent)
Serialize the "variables" member.
Default: true
Example:
Example result for query Position, (Likes, _Food)
Serialize the "is_set" member.
Default: true
Example:
Example result for query Position, ?Velocity
Serialize the "values" member.
Default: true
Example:
Example result for query Position
Serialize the "entities" member.
Default: true
Example:
Serialize the "entity_labels" member.
Default: false
Example:
Serialize the "variable_labels" member.
Default: false
Example:
Serialize the "eval_duration" member.
Default: false
Example:
Serialize the "type_info" member.
Default: false
Example: