I have JSON data that contains a key called reportData with an array of values:
{"reportData":[
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"],
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","01","19065","FB01"],
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]}
I need to compare and interchange data in each array element, specifically at the 12th and 14th indexes.
For example, in "reportData":[
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","20","23840","FF20"]]
This means I want to compare and swap '20' with 'FF20' using the following logic:
If the value at the 14th index is not null, then assign,
The value at the 12th index = the value at the 14th index.
If the value at the 14th index is null,
then leave the value at the 12th index as it is.
This process needs to be repeated for all arrays in the "reportData" key.
Therefore, my final JSON should look like this,
"reportData":[
["1185","R","4t","G","06","L","GT","04309","2546","2015","CF FE","01H1","FF20","23840","FF20"],//interchange 12th with 14th if 14th is not null
["1186","R","5t","R","01","L","TP","00110","1854","2016","FE LL","06W3","FB01","19065","FB01"],//interchange 12th with 14th if 14th is not null
["1187","R","6t","H","06","L","TP","04333","1864","2015","CF FE SL","0209","FD22","19845",null],//leave 12th as it is since 14th is null
["1188","R","7t","H","06","L","PR","04041","6951","2015","CC CT FE GN PC","0070","00","36590","LB00"],//interchange 12th with 14th if 14th is not null
["1189","R","8t","H","06","L","WS","04290","4450","2014","CF EN FE PC TP","0070","EA30","28320.00",null],//leave 12th as it is since 14th is null
["1190","R","9t","H","06","L","LA","04915","4430","2015","CF DK FE RR TC","0040","10","23680","FB10"],//interchange 12th with 14th if 14th is not null
["1191","R","10t","H","06","L","LF","04335","2532","2015","CF FE GE","0040","FC10","22970",null],//leave 12th as it is since 14th is null
["1192","R","11t","H","06","L","SA","04772","8345","2015","BZ C8 FE","01D6","13","33390","LC13"]]//interchange 12th with 14th if 14th is not null
I tried a function but it didn't work as expected. Can anyone help me resolve this issue?