Overwrite with Sequential Numbers (Dedicated 2D Array)


using JSON Pointer..

ASTER::ACTION::JSON::Overwrite 2D Array Elements with Sequential Numbers.

Assign “Sequential Numbering” to the specified elements in a two-dimensional array.

  • This is a JSON data editing function dedicated to two-dimensional arrays.

  • This overwrite command does not perform type checking in advance.

  • Please note that the data type of the path-specified value will be forcibly overwritten to a numeric type.


Function Overview

Perform loop processing that narrows down the range of array elements in the path-specified JSON array and assigns sequential numbers to the array elements.


Parameter.1

Specify JSON Pointer

Assume the following JSON data is loaded in memory as a sample.

{
     "test":[
          [true, -1],
          [true, -1],
          [true, -1]
     ]
}

"/test" is a two-dimensional array. As a sample parameter, the following:

"/test/0/1"
Description of the image
Parameter.1 specifies the position of the two-dimensional array as a JSON Pointer. It also checks the type to ensure that the key name "test" is a two-dimensional array. If the type does not match, an error notification is displayed, the process is interrupted, and the command execution ends.

Type checking is performed as follows.

/test/0    <!--  is an array -->
/test/0/true
/test/0/-1
/test/1    <!--  is an array = ( here it is determined as a two-dimensional array ) -->
/test/1/true
/test/1/-1
/test/2    <!--  no further type checking -->
/test/2/true
/test/2/-1

Parameter.1 requires a description that includes specifying array elements.

This array element specifies the starting position for the loop processing execution.

"/test/0/1" specifies that the array element to be processed in the loop starts from 0.

Here, we will temporarily skip the explanation of Parameter.2 and first show the result of rewriting using the above parameter.

Show result…
{
     "test":[
          [true, 1],
          [true, 2],
          [true, 3]
     ]
}

Parameter.2 sets the loop processing configurations.


Parameter.2

Serialize multiple “integer” data into a single parameter and send it to ASTER.

Format checking is enabled; if invalid data is entered, a format error is displayed. If a format error occurs, all processing is interrupted, and the command is terminated.

As a sample where "/test" is a two-dimensional array containing 3 array types and the number of loop processing is specified as 3, the following:

" 3 , 1 , +1 "
param Type Description
3 unsigned int Number of loop iterations (negative values are errors)
1 int Starting number for sequential numbering
+1 int Increment/decrement value for sequential numbering: use of sign for readability is recommended

Set the number of loop iterations and the starting number and increment/decrement value for sequential numbering. Parameter.1 specifies the loop start position, and the loop iteration count in Parameter.2 adjusts the loop end position.

Here is the execution result using the sample Parameter.1 and the current Parameter.2:

Show Param.1 and Param.2…
{
     "test":[
          [true, -1],
          [true, -1],
          [true, -1]
     ]
}
"/test/0/1"
" 3 , 1 , +1 "
{
     "test":[
          [true, 1],
          [true, 2],
          [true, 3]
     ]
}

Example of Format Error

Read more…

The number of loop iterations is a negative value

"-1,  0,  +1"

Use of Floating-Point Numbers

" 3,  -10,  +0.1"

Remarks.1

Type Check

Read more…

The JSON format array type can store data mixed with different types. If "/test/0" is an array, the next "/test/1" and "/test/2" may not be arrays, but it is a two-dimensional array.

In other words, type checking is performed beforehand but is intentionally not strict. To avoid errors, it is the creator’s responsibility to prepare arrays that conform to the specifications in advance.


Remarks.2

Plus-Minus Sign

Read more…

Parameter.2 can use a plus-minus sign for the increment/decrement value for sequential numbering.

Below are the sample parameters and their results.

"/test/0/1"
"3, 10, -10"
{
     "test":[
          [true,  10],
          [true,   0],
          [true, -10]
     ]
}

Remarks.3

Loop Start Position and Loop End Position

Read more…

By combining the specification of Parameter.1 and the setting of Parameter.2, you can adjust the loop start position and the loop end position.

For example, you can specify a loop that skips "/test/0" and starts the sequential numbering from "/test/1".

{
     "test":[
          [true, 100],
          [true, 200],
          [true, 300]
     ]
}
"/test/1/1"
"2, -400, +400"
{
     "test":[
          [true,   100],
          [true,  -400],
          [true,     0]
     ]
}

Loop Count Specification

Read more…

Specifying the loop count in Parameter.2 will not result in an error even if a value greater than the number of array elements is specified. Internally, if the loop count exceeds the number of array elements, any subsequent processing is implicitly canceled.