Targeted JSON Pointer: is_array: Batch Assign Oi Variables, Strings, & Flags
using Targeted JSON Pointer..
ASTER::ACTION::JSON::Targeted JSON Pointer::is_array: Inject across Oi Variables & Strings & Flags
Store JSON Objects within the elements of a JSON Array, specify the JSON Array with a Targeted JSON Pointer, and perform bulk assignment of values to instance variables.
-
Utilizes a pre-configured Targeted JSON Pointer.
-
The target is a JSON Array with the each data elements is a JSON Object, the function supports to inject the 3-data tyeps as “booleans”, “strings”, “Numeric values”:
Parameter
Select the object instance. Only the "Active (sprite) Object" Type can be registered to the controller.
If "The Active Object" is not specified, an error will be displayed when executing the action from the event, and the registration process will be aborted.
Function Overviews
This function performs bulk assignment of values to the CF25 Active Object’s mutable variables, mutable string variables, and flags.
The values to be assigned are limited to three types contained in the JSON Object: numeric, string, and boolean; any other data types are skipped internally.
Data to be copied into instance variables must be described in the JSON Object.
To support multiple instances, store JSON Objects as elements of an array. Below is a sample.
{
"JSON_Array":[
{
"id":18,
"flag_1":true,
"falg_2":false,
"about":"details about...",
"falg_3":true,
"poem":"such a nice string data",
"scale":0.5
}
]
}The above JSON object, after deserialization, has its values sorted in ascending order according to their stored data types, and then the values are copied into the variables of the object instance specified by the parameter.
CF25 Object Properties
CF25 provides a feature that allows access to an object’s mutable variables from the Properties panel in the frame editor and enables data editing before execution.
However, when accessed via the Properties panel, it becomes a bulk assignment to object instances, so you cannot select individual instances of the same object and assign different values to each instance.
Using ASTER’s bulk-assignment feature for object instances, Developers can edit JSON objects in their preferred text editor and copy data to instances at any time after the application runs. The ability to list different data types as text and manage them centrally is another convenience.
By adding JSON objects to a JSON array according to the number of instances, you can support multiple instances.
Note:
When you load a
.jsonfile and use it in ASTER, the order of the data matches the insertion order. Sorting by key names is not performed.
If you save the data in MessagePack, the insertion order is not guaranteed and the data will be ordered by key names. Below is a sample.
{
"JSON_Array":[
{
"about":"details about...",
"falg_2":false,
"falg_3":true,
"flag_1":true,
"id":18,
"poem":"such a nice string data",
"scale":0.5
}
]
}"/JSON_Array/0/falg_2" is intentionally left misspelled.
With the correct key name, "flag_1" was intended to appear first among Boolean-typed data, but because it was mistakenly written as falg, the data sort places falg_2 at the top.
If the data insertion order looks wrong, consider these two possibilities:
- You mistyped a key name
- Sorting by key name took effect (MessagePack)
For more details on the behavior of nlohmann::json, see more details below.
JSON data types
The basic JSON structure starts with either a JSON Object or a JSON Array, and the data types that can be used within them are the following six types.
| Type | Example | Description |
|---|---|---|
| objects | {"key": "value"} |
A collection of key–value pairs (associative array) |
| arrays | [1, 2, 3] |
An ordered list of values |
| strings | "Hello" |
A string (must be enclosed in double quotes) |
| numbers | 42, 3.14 |
Numeric values (no distinction between integers and floating point) |
| booleans | true, false |
Boolean values |
| null | null |
Represents the absence of a value |
About numbers
The JSON specification ( RFC 8259: #section-6 ) defines numbers as “not strictly distinguished between integers and fractions”. In other words, there is a single abstract numeric type called numbers and no further subtype distinction.
Implementations are allowed to impose limits on range and precision, so software authors choose numeric representations that approximate values within an interoperable precision.
ASTER uses the nlohmann::json (C++) library, so the default numeric type handled in JSON is double (IEEE 754). However, integer values within range can be preserved as int64_t; these behaviors follow the nlohmann::json implementation.
CF25 specifies numeric types as int (32 bit) and float, and does not normally support double. Although extensions internally use double for numeric processing, values passed to CF25 are converted to the target types, reducing precision. Rounding errors that occur at this conversion step are unavoidable by specification, so please be aware.
- If numeric precision is critical, it is safer to store the value as a string rather than as a numeric type when exchanging data.
About JSON Object
JSON handles two data structures: Object and Array.
An Object is a data format composed of key–value pairs and corresponds to an associative array.
{
"key":"value"
}nlohmann/json (C++) by default implements:
- JSON Array as
std::vector - JSON Object as
std::map<std::string, json>
Therefore, keys are sorted in lexicographical order and insertion order is not preserved.
ASTER (~ rev.1.0.7) uses using json = nlohmann::ordered_json;, so insertion order is preserved and automatic key sorting is not performed.
| Version | Type used | Order preserved | Sorted | Internal structure |
|---|---|---|---|---|
| ASTER (~ rev.1.0.7) | ordered_json |
✅ yes | ❌ no | std::vector<pair<...>> |
| nlohmann/json | json (default) |
❌ no | ✅ yes | std::map |
- When saved in
MessagePackformat, even ifordered_jsonis used, it is internally converted tojson(i.e.,basic_json<std::map>) before encoding, so the MessagePack binary stores keys in lexicographical order and they will be restored in that order.
