JSON Pointer: Retrieve the data type as numeric
using JSON Pointer..
ASTER::EXPRESSION::JSON::Using JSON Pointer; Get As Num
Retrieve data as a numerical value from the path specified by the JSON Pointer.
CF25 is a 32-bit application, and numerical values are preferentially handled using lower-precision types (long type = 32-bit signed integer, floating-point numbers are of float type).
In nlohmann/json, when using floating-point numbers or scientific notation, numerical values are always stored as double (64-bit) by default.
- Relevant URL : Number Handling ( JSON for Modern C++ )
About Type Conversion
Specifications and Limitations of Numerical Values in CF25
There is a gap in the range of representable numerical values between CF25 and nlohmann/json. To transfer accurate values without being affected by rounding errors caused by type conversion, the only solution is to convert numerical values into strings.
For example, the float
type can represent up to 7 digits
. However, since this includes both the integer part and the decimal part, the actual range of values that can be handled in CF25 is significantly less precise compared to double
.
It has been confirmed that the upper limit of the long int
type in CF25 (32-bit integer type) is 2,147,483,647, which corresponds to the range -2,147,483,648 to 2,147,483,647
.
Parameter
Assuming that the JSON data below is preloaded into memory, specify the JSON Pointer.
{
"test":12345,
"array":[
555,
666,
193
]
}
JSON consists of pairs of key names and values. To obtain the numerical value 12345
from the key name “test,” describe the JSON Pointer as follows.
"/test"
ExNum( "ASTER", "/test" )
To retrieve the number 193
by specifying an array element from a JSON array with the key name ‘array,’ specify the JSON Pointer as follows.
ExNum( "ASTER", "/array/2" )
Flatten Dump can flatten hierarchical structures and is useful for debugging purposes.
{
"/test":12345,
"/array/0":555,
"/array/1":666,
"/array/2":193,
}