Related
I am using Oracle Apex 22.2 and Oracle Database XE 21c on CentOS 7. I want to loop through all the nested elements in a JSON document/CLOB and achieve the Canonical String (shown below). Also, any suggestions on improving my procedure or on a different solution to handle this would be appreciated. I wrote my own procedure shown below following the algorithm shown below. All help and suggestions are really appreciated.
Algorithm Pseudo Code
function string Serialize(documentStructure)
if documentStructure is simple value type
return """ + documentStructure.value + """
end if
var serializedString = ""
foreach element in the structure:
if element is not array type
serializeString.Append (""" + element.name.uppercase + """)
serializeString.Append ( Serialize(element.value) )
end if
if element is of array type
serializeString.Append (""" + element.name.uppercase + """)
foreach array element in element:
// use below line for JSON because subelements of array in JSON do not have own names
serializeString.Append (""" + element.name.uppercase + """)
serializeString.Append ( Serialize(arrayelement.value) )
end foreach
end if
end foreach
return serializedString
end function
Procedure Code
create or replace PROCEDURE ETA_JSON_SERIALIZE (json_in IN JSON_ELEMENT_T, can_str IN OUT VARCHAR2)
IS
l_object JSON_OBJECT_T;
l_array JSON_ARRAY_T;
l_keys JSON_KEY_LIST;
l_str VARCHAR2(32767);
BEGIN
FOR i IN 1 .. json_in.get_Size LOOP
IF json_in.is_Scalar() THEN
IF json_in.is_String() THEN
l_str := '"' || json_in.to_String() || '" 1st Line Break' || CHR(10);
DBMS_OUTPUT.PUT_LINE(l_str);
RETURN;
ELSIF json_in.is_Number() THEN
l_str := '"' || json_in.to_Number() || '" 2nd Line Break' || CHR(10);
DBMS_OUTPUT.PUT_LINE(l_str);
RETURN;
ELSE
l_str := 'Other Scalar' || ' 3rd Line Break' || CHR(10);
DBMS_OUTPUT.PUT_LINE(l_str);
END IF;
ELSIF json_in.is_Object() THEN
-- l_str := 'Object:' || CHR(10);
-- DBMS_OUTPUT.PUT_LINE(l_str);
l_object := JSON_OBJECT_T( json_in );
-- l_object.on_Error(1);
l_keys := l_object.get_Keys();
-- l_str := ' Element Size: ' || json_in.get_Size || CHR(10);
-- l_str := ' Key Count: ' || l_keys.COUNT || CHR(10);
-- DBMS_OUTPUT.PUT_LINE(l_str);
l_str := UPPER(l_keys(i)) || ' 4th Line Break' || CHR(10);
DBMS_OUTPUT.PUT_LINE(l_str);
ETA_JSON_SERIALIZE( l_object.get( l_keys(i) ), l_str );
ELSIF json_in.is_Array() THEN
-- l_str := l_str || 'Array:' || CHR(10);
-- DBMS_OUTPUT.PUT_LINE(l_str);
l_array := JSON_ARRAY_T( json_in );
-- l_array.on_Error(1);
-- l_str := ' Element Size: ' || json_in.get_Size || CHR(10);
-- DBMS_OUTPUT.PUT_LINE(l_str);
-- l_str := ' Array Size: ' || l_array.get_Size || CHR(10);
-- DBMS_OUTPUT.PUT_LINE(l_str);
-- FOR j IN 0 .. l_array.get_Size - 1 LOOP
ETA_JSON_SERIALIZE( l_array.get(i - 1), l_str );
-- END LOOP;
ELSE
l_str := 'Other Type' || CHR(10) || '5th Line Break' || CHR(10);
DBMS_OUTPUT.PUT_LINE(l_str);
END IF;
END LOOP;
can_str := l_str;
END;
PL/SQL Block
SET SERVEROUTPUT ON
DECLARE
can_str VARCHAR2(32767);
l_element JSON_ELEMENT_T;
l_element1 JSON_ELEMENT_T;
l_object JSON_OBJECT_T;
l_keys JSON_KEY_LIST;
l_doc CLOB := '{a:100, b:200, c:300}';
l_doc1 CLOB := '{
"department": "Accounting",
"employees": [
{
"name": "Shelley,Higgins",
"job": "Accounting Manager"
},
{
"name": "William,Gietz",
"job": "Public Accountant"
}
]
}';
l_doc2 CLOB := '{
"REQS": {
"INDICATOR": "Y",
"NUMBER": 0,
"CATEGORY": "TU",
"ID_R": 10888,
"SUPPL_VAL": 0,
"LINE_ITEMSSUB": {
"QTY": 0,
"TOTAL_QTY": 1,
"PIPE": {
"P_CODE": 9801,
"P_ID": 7500030,
"CC_CODE": "C6AJG4"
}
}
},
"Name": "Rajesh",
"Age": 47
}';
l_doc3 CLOB := '{
"documents": [{
"issuer": {
"type": "B",
"id": "301188475",
"name": "Hakim Misr Paco (POS-0)",
"address": {
"branchID": "-1",
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "Mostafa El Nahas",
"buildingNumber": "65"
}
},
"receiver": {
"type": "P",
"id": " 29409200104255",
"name": "Karim Ahmed Abdelhakim Hashem",
"address": {
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "Mostafa El Nahas",
"buildingNumber": "65"
}
},
"documentType": "I",
"documentTypeVersion": "0.9",
"dateTimeIssued": "2022-11-19T23:59:59Z",
"taxpayerActivityCode": "2220",
"internalID": "0-1",
"invoiceLines": [{
"description": "KFC_Test",
"itemType": "GS1",
"itemCode": "10006331",
"unitType": "EA",
"quantity": 1000,
"unitValue": {
"currencySold": "EGP",
"amountEGP": 0.10000,
"amountSold": 0
},
"salesTotal": 100,
"total": 114,
"valueDifference": 0,
"totalTaxableFees": 0,
"netTotal": 100,
"itemsDiscount": 0,
"discount": {
"rate": 0,
"amount": 0
},
"taxableItems": [{
"taxType": "T1",
"amount": 14,
"subType": "V009",
"rate": 14
}],
"internalCode": "Test_110"
}],
"totalSalesAmount": 100,
"totalDiscountAmount": 0,
"netAmount": 100,
"taxTotals": [{
"taxType": "T1",
"amount": 14
}],
"extraDiscountAmount": 0,
"totalItemsDiscountAmount": 0,
"totalAmount": 114,
"signatures": [{
"signatureType": "I",
"value": "NA"
}]
}]
}';
BEGIN
l_element := JSON_ELEMENT_T.parse( l_doc3 );
ETA_JSON_SERIALIZE(l_element, can_str);
DBMS_OUTPUT.PUT_LINE(can_str);
END;
/
JSON Format
<pre>
{
"issuer": {
"address": {
"branchID": "1",
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "580 Clementina Key",
"buildingNumber": "Bldg. 0",
"postalCode": "68030",
"floor": "1",
"room": "123",
"landmark": "7660 Melody Trail",
"additionalInformation": "beside Townhall"
},
"type": "B",
"id": "113317713",
"name": "Issuer Company"
},
"receiver": {
"address": {
"country": "EG",
"governate": "Egypt",
"regionCity": "Mufazat al Ismlyah",
"street": "580 Clementina Key",
"buildingNumber": "Bldg. 0",
"postalCode": "68030",
"floor": "1",
"room": "123",
"landmark": "7660 Melody Trail",
"additionalInformation": "beside Townhall"
},
"type": "B",
"id": "313717919",
"name": "Receiver"
},
"documentType": "I",
"documentTypeVersion": "0.9",
"dateTimeIssued": "2020-10-27T23:59:59Z",
"taxpayerActivityCode": "4620",
"internalID": "IID1",
"purchaseOrderReference": "P-233-A6375",
"purchaseOrderDescription": "purchase Order description",
"salesOrderReference": "1231",
"salesOrderDescription": "Sales Order description",
"proformaInvoiceNumber": "SomeValue",
"payment": {
"bankName": "SomeValue",
"bankAddress": "SomeValue",
"bankAccountNo": "SomeValue",
"bankAccountIBAN": "",
"swiftCode": "",
"terms": "SomeValue"
},
"delivery": {
"approach": "SomeValue",
"packaging": "SomeValue",
"dateValidity": "2020-09-28T09:30:10Z",
"exportPort": "SomeValue",
"countryOfOrigin": "EG",
"grossWeight": 10.50,
"netWeight": 20.50,
"terms": "SomeValue"
},
"invoiceLines": [
{
"description": "Computer1",
"itemType": "GPC",
"itemCode": "10001774",
"unitType": "EA",
"quantity": 5,
"internalCode": "IC0",
"salesTotal": 947.00,
"total": 2969.89,
"valueDifference": 7.00,
"totalTaxableFees": 817.42,
"netTotal": 880.71,
"itemsDiscount": 5.00,
"unitValue": {
"currencySold": "EUR",
"amountEGP": 189.40,
"amountSold": 10.00,
"currencyExchangeRate": 18.94
},
"discount": {
"rate": 7,
"amount": 66.29
},
"taxableItems": [
{
"taxType": "T1",
"amount": 272.07,
"subType": "T1",
"rate": 14.00
},
{
"taxType": "T2",
"amount": 208.22,
"subType": "T2",
"rate": 12
},
{
"taxType": "T3",
"amount": 30.00,
"subType": "T3",
"rate": 0.00
},
{
"taxType": "T4",
"amount": 43.79,
"subType": "T4",
"rate": 5.00
},
{
"taxType": "T5",
"amount": 123.30,
"subType": "T5",
"rate": 14.00
},
{
"taxType": "T6",
"amount": 60.00,
"subType": "T6",
"rate": 0.00
},
{
"taxType": "T7",
"amount": 88.07,
"subType": "T7",
"rate": 10.00
},
{
"taxType": "T8",
"amount": 123.30,
"subType": "T8",
"rate": 14.00
},
{
"taxType": "T9",
"amount": 105.69,
"subType": "T9",
"rate": 12.00
},
{
"taxType": "T10",
"amount": 88.07,
"subType": "T10",
"rate": 10.00
},
{
"taxType": "T11",
"amount": 123.30,
"subType": "T11",
"rate": 14.00
},
{
"taxType": "T12",
"amount": 105.69,
"subType": "T12",
"rate": 12.00
},
{
"taxType": "T13",
"amount": 88.07,
"subType": "T13",
"rate": 10.00
},
{
"taxType": "T14",
"amount": 123.30,
"subType": "T14",
"rate": 14.00
},
{
"taxType": "T15",
"amount": 105.69,
"subType": "T15",
"rate": 12.00
},
{
"taxType": "T16",
"amount": 88.07,
"subType": "T16",
"rate": 10.00
},
{
"taxType": "T17",
"amount": 88.07,
"subType": "T17",
"rate": 10.00
},
{
"taxType": "T18",
"amount": 123.30,
"subType": "T18",
"rate": 14.00
},
{
"taxType": "T19",
"amount": 105.69,
"subType": "T19",
"rate": 12.00
},
{
"taxType": "T20",
"amount": 88.07,
"subType": "T20",
"rate": 10.00
}
]
},
{
"description": "Computer2",
"itemType": "GPC",
"itemCode": "10003752",
"unitType": "EA",
"quantity": 7,
"internalCode": "IC0",
"salesTotal": 662.90,
"total": 2226.61,
"valueDifference": 6.00,
"totalTaxableFees": 621.51,
"netTotal": 652.90,
"itemsDiscount": 9.00,
"unitValue": {
"currencySold": "EUR",
"amountEGP": 94.70,
"amountSold": 5.00,
"currencyExchangeRate": 18.94
},
"discount": {
"rate": 0,
"amount": 10.00
},
"taxableItems": [
{
"taxType": "T1",
"amount": 205.47,
"subType": "T1",
"rate": 14.00
},
{
"taxType": "T2",
"amount": 157.25,
"subType": "T2",
"rate": 12
},
{
"taxType": "T3",
"amount": 30.00,
"subType": "T3",
"rate": 0.00
},
{
"taxType": "T4",
"amount": 32.20,
"subType": "T4",
"rate": 5.00
},
{
"taxType": "T5",
"amount": 91.41,
"subType": "T5",
"rate": 14.00
},
{
"taxType": "T6",
"amount": 60.00,
"subType": "T6",
"rate": 0.00
},
{
"taxType": "T7",
"amount": 65.29,
"subType": "T7",
"rate": 10.00
},
{
"taxType": "T8",
"amount": 91.41,
"subType": "T8",
"rate": 14.00
},
{
"taxType": "T9",
"amount": 78.35,
"subType": "T9",
"rate": 12.00
},
{
"taxType": "T10",
"amount": 65.29,
"subType": "T10",
"rate": 10.00
},
{
"taxType": "T11",
"amount": 91.41,
"subType": "T11",
"rate": 14.00
},
{
"taxType": "T12",
"amount": 78.35,
"subType": "T12",
"rate": 12.00
},
{
"taxType": "T13",
"amount": 65.29,
"subType": "T13",
"rate": 10.00
},
{
"taxType": "T14",
"amount": 91.41,
"subType": "T14",
"rate": 14.00
},
{
"taxType": "T15",
"amount": 78.35,
"subType": "T15",
"rate": 12.00
},
{
"taxType": "T16",
"amount": 65.29,
"subType": "T16",
"rate": 10.00
},
{
"taxType": "T17",
"amount": 65.29,
"subType": "T17",
"rate": 10.00
},
{
"taxType": "T18",
"amount": 91.41,
"subType": "T18",
"rate": 14.00
},
{
"taxType": "T19",
"amount": 78.35,
"subType": "T19",
"rate": 12.00
},
{
"taxType": "T20",
"amount": 65.29,
"subType": "T20",
"rate": 10.00
}
]
}
],
"totalDiscountAmount": 76.29,
"totalSalesAmount": 1609.90,
"netAmount": 1533.61,
"taxTotals": [
{
"taxType": "T1",
"amount": 477.54
},
{
"taxType": "T2",
"amount": 365.47
},
{
"taxType": "T3",
"amount": 60.00
},
{
"taxType": "T4",
"amount": 75.99
},
{
"taxType": "T5",
"amount": 214.71
},
{
"taxType": "T6",
"amount": 120.00
},
{
"taxType": "T7",
"amount": 153.36
},
{
"taxType": "T8",
"amount": 214.71
},
{
"taxType": "T9",
"amount": 184.04
},
{
"taxType": "T10",
"amount": 153.36
},
{
"taxType": "T11",
"amount": 214.71
},
{
"taxType": "T12",
"amount": 184.04
},
{
"taxType": "T13",
"amount": 153.36
},
{
"taxType": "T14",
"amount": 214.71
},
{
"taxType": "T15",
"amount": 184.04
},
{
"taxType": "T16",
"amount": 153.36
},
{
"taxType": "T17",
"amount": 153.36
},
{
"taxType": "T18",
"amount": 214.71
},
{
"taxType": "T19",
"amount": 184.04
},
{
"taxType": "T20",
"amount": 153.36
}
],
"totalAmount": 5191.50,
"extraDiscountAmount": 5.00,
"totalItemsDiscountAmount": 14.00
}
Canonical String
"ISSUER""ADDRESS""BRANCHID""1""COUNTRY""EG""GOVERNATE""Cairo""REGIONCITY""Nasr City""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""113317713""NAME""Issuer Company""RECEIVER""ADDRESS""COUNTRY""EG""GOVERNATE""Egypt""REGIONCITY""Mufazat al Ismlyah""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""313717919""NAME""Receiver""DOCUMENTTYPE""I""DOCUMENTTYPEVERSION""0.9""DATETIMEISSUED""2020-10-27T23:59:59Z""TAXPAYERACTIVITYCODE""4620""INTERNALID""IID1""PURCHASEORDERREFERENCE""P-233-A6375""PURCHASEORDERDESCRIPTION""purchase Order description""SALESORDERREFERENCE""1231""SALESORDERDESCRIPTION""Sales Order description""PROFORMAINVOICENUMBER""SomeValue""PAYMENT""BANKNAME""SomeValue""BANKADDRESS""SomeValue""BANKACCOUNTNO""SomeValue""BANKACCOUNTIBAN""""SWIFTCODE""""TERMS""SomeValue""DELIVERY""APPROACH""SomeValue""PACKAGING""SomeValue""DATEVALIDITY""2020-09-28T09:30:10Z""EXPORTPORT""SomeValue""COUNTRYOFORIGIN""EG""GROSSWEIGHT""10.50""NETWEIGHT""20.50""TERMS""SomeValue""INVOICELINES""INVOICELINES""DESCRIPTION""Computer1""ITEMTYPE""GPC""ITEMCODE""10001774""UNITTYPE""EA""QUANTITY""5""INTERNALCODE""IC0""SALESTOTAL""947.00""TOTAL""2969.89""VALUEDIFFERENCE""7.00""TOTALTAXABLEFEES""817.42""NETTOTAL""880.71""ITEMSDISCOUNT""5.00""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""189.40""AMOUNTSOLD""10.00""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""7""AMOUNT""66.29""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""272.07""SUBTYPE""T1""RATE""14.00""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""208.22""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30.00""SUBTYPE""T3""RATE""0.00""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""43.79""SUBTYPE""T4""RATE""5.00""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""123.30""SUBTYPE""T5""RATE""14.00""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60.00""SUBTYPE""T6""RATE""0.00""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""88.07""SUBTYPE""T7""RATE""10.00""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""123.30""SUBTYPE""T8""RATE""14.00""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""105.69""SUBTYPE""T9""RATE""12.00""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""88.07""SUBTYPE""T10""RATE""10.00""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""123.30""SUBTYPE""T11""RATE""14.00""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""105.69""SUBTYPE""T12""RATE""12.00""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""88.07""SUBTYPE""T13""RATE""10.00""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""123.30""SUBTYPE""T14""RATE""14.00""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""105.69""SUBTYPE""T15""RATE""12.00""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""88.07""SUBTYPE""T16""RATE""10.00""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""88.07""SUBTYPE""T17""RATE""10.00""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""123.30""SUBTYPE""T18""RATE""14.00""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""105.69""SUBTYPE""T19""RATE""12.00""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""88.07""SUBTYPE""T20""RATE""10.00""INVOICELINES""DESCRIPTION""Computer2""ITEMTYPE""GPC""ITEMCODE""10003752""UNITTYPE""EA""QUANTITY""7""INTERNALCODE""IC0""SALESTOTAL""662.90""TOTAL""2226.61""VALUEDIFFERENCE""6.00""TOTALTAXABLEFEES""621.51""NETTOTAL""652.90""ITEMSDISCOUNT""9.00""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""94.70""AMOUNTSOLD""5.00""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""0""AMOUNT""10.00""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""205.47""SUBTYPE""T1""RATE""14.00""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""157.25""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30.00""SUBTYPE""T3""RATE""0.00""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""32.20""SUBTYPE""T4""RATE""5.00""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""91.41""SUBTYPE""T5""RATE""14.00""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60.00""SUBTYPE""T6""RATE""0.00""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""65.29""SUBTYPE""T7""RATE""10.00""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""91.41""SUBTYPE""T8""RATE""14.00""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""78.35""SUBTYPE""T9""RATE""12.00""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""65.29""SUBTYPE""T10""RATE""10.00""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""91.41""SUBTYPE""T11""RATE""14.00""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""78.35""SUBTYPE""T12""RATE""12.00""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""65.29""SUBTYPE""T13""RATE""10.00""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""91.41""SUBTYPE""T14""RATE""14.00""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""78.35""SUBTYPE""T15""RATE""12.00""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""65.29""SUBTYPE""T16""RATE""10.00""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""65.29""SUBTYPE""T17""RATE""10.00""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""91.41""SUBTYPE""T18""RATE""14.00""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""78.35""SUBTYPE""T19""RATE""12.00""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""65.29""SUBTYPE""T20""RATE""10.00""TOTALDISCOUNTAMOUNT""76.29""TOTALSALESAMOUNT""1609.90""NETAMOUNT""1533.61""TAXTOTALS""TAXTOTALS""TAXTYPE""T1""AMOUNT""477.54""TAXTOTALS""TAXTYPE""T2""AMOUNT""365.47""TAXTOTALS""TAXTYPE""T3""AMOUNT""60.00""TAXTOTALS""TAXTYPE""T4""AMOUNT""75.99""TAXTOTALS""TAXTYPE""T5""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T6""AMOUNT""120.00""TAXTOTALS""TAXTYPE""T7""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T8""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T9""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T10""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T11""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T12""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T13""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T14""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T15""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T16""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T17""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T18""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T19""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T20""AMOUNT""153.36""TOTALAMOUNT""5191.50""EXTRADISCOUNTAMOUNT""5.00""TOTALITEMSDISCOUNTAMOUNT""14.00"
You can use:
create or replace PROCEDURE ETA_JSON_SERIALIZE (
json_in IN JSON_ELEMENT_T,
can_str IN OUT VARCHAR2,
object_key IN VARCHAR2 DEFAULT NULL
)
IS
BEGIN
IF json_in.is_Object() THEN
DECLARE
l_object JSON_OBJECT_T := TREAT(json_in AS JSON_OBJECT_T);
l_keys JSON_KEY_LIST := l_object.get_Keys();
BEGIN
FOR i IN 1 .. l_keys.COUNT LOOP
can_str := can_str || '"'||UPPER(l_keys(i))||'"';
ETA_JSON_SERIALIZE(l_object.get(l_keys(i)), can_str, l_keys(i));
END LOOP;
END;
ELSIF json_in.is_Array() THEN
DECLARE
l_array JSON_ARRAY_T := TREAT(json_in AS JSON_ARRAY_T);
BEGIN
FOR i IN 0 .. l_array.get_size -1 LOOP
IF i > 0 AND object_key IS NOT NULL THEN
can_str := can_str || '"'||UPPER(object_key)||'"';
END IF;
ETA_JSON_SERIALIZE(l_array.get(i), can_str);
END LOOP;
END;
ELSIF json_in.is_Scalar() THEN
can_str := can_str || json_in.to_String();
END IF;
END;
/
Which, for the sample data:
DECLARE
can_str VARCHAR2(32767);
l_element JSON_ELEMENT_T;
l_doc CLOB := '{
"documents": [{
"issuer": {
"type": "B",
"id": "301188475",
"name": "Hakim Misr Paco (POS-0)",
"address": {
"branchID": "-1",
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "Mostafa El Nahas",
"buildingNumber": "65"
}
},
"receiver": {
"type": "P",
"id": " 29409200104255",
"name": "Karim Ahmed Abdelhakim Hashem",
"address": {
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "Mostafa El Nahas",
"buildingNumber": "65"
}
},
"documentType": "I",
"documentTypeVersion": "0.9",
"dateTimeIssued": "2022-11-19T23:59:59Z",
"taxpayerActivityCode": "2220",
"internalID": "0-1",
"invoiceLines": [{
"description": "KFC_Test",
"itemType": "GS1",
"itemCode": "10006331",
"unitType": "EA",
"quantity": 1000,
"unitValue": {
"currencySold": "EGP",
"amountEGP": 0.10000,
"amountSold": 0
},
"salesTotal": 100,
"total": 114,
"valueDifference": 0,
"totalTaxableFees": 0,
"netTotal": 100,
"itemsDiscount": 0,
"discount": {
"rate": 0,
"amount": 0
},
"taxableItems": [{
"taxType": "T1",
"amount": 14,
"subType": "V009",
"rate": 14
}],
"internalCode": "Test_110"
}],
"totalSalesAmount": 100,
"totalDiscountAmount": 0,
"netAmount": 100,
"taxTotals": [{
"taxType": "T1",
"amount": 14
}],
"extraDiscountAmount": 0,
"totalItemsDiscountAmount": 0,
"totalAmount": 114,
"signatures": [{
"signatureType": "I",
"value": "NA"
}]
}]
}';
BEGIN
ETA_JSON_SERIALIZE(JSON_ELEMENT_T.parse( l_doc ), can_str);
DBMS_OUTPUT.PUT_LINE(can_str);
END;
/
Outputs:
"DOCUMENTS""ISSUER""TYPE""B""ID""301188475""NAME""Hakim Misr Paco (POS-0)""ADDRESS""BRANCHID""-1""COUNTRY""EG""GOVERNATE""Cairo""REGIONCITY""Nasr City""STREET""Mostafa El Nahas""BUILDINGNUMBER""65""RECEIVER""TYPE""P""ID"" 29409200104255""NAME""Karim Ahmed Abdelhakim Hashem""ADDRESS""COUNTRY""EG""GOVERNATE""Cairo""REGIONCITY""Nasr City""STREET""Mostafa El Nahas""BUILDINGNUMBER""65""DOCUMENTTYPE""I""DOCUMENTTYPEVERSION""0.9""DATETIMEISSUED""2022-11-19T23:59:59Z""TAXPAYERACTIVITYCODE""2220""INTERNALID""0-1""INVOICELINES""DESCRIPTION""KFC_Test""ITEMTYPE""GS1""ITEMCODE""10006331""UNITTYPE""EA""QUANTITY"1000"UNITVALUE""CURRENCYSOLD""EGP""AMOUNTEGP"0.10000"AMOUNTSOLD"0"SALESTOTAL"100"TOTAL"114"VALUEDIFFERENCE"0"TOTALTAXABLEFEES"0"NETTOTAL"100"ITEMSDISCOUNT"0"DISCOUNT""RATE"0"AMOUNT"0"TAXABLEITEMS""TAXTYPE""T1""AMOUNT"14"SUBTYPE""V009""RATE"14"INTERNALCODE""Test_110""TOTALSALESAMOUNT"100"TOTALDISCOUNTAMOUNT"0"NETAMOUNT"100"TAXTOTALS""TAXTYPE""T1""AMOUNT"14"EXTRADISCOUNTAMOUNT"0"TOTALITEMSDISCOUNTAMOUNT"0"TOTALAMOUNT"114"SIGNATURES""SIGNATURETYPE""I""VALUE""NA"
fiddle
I am using Oracle Apex 22.2 and Oracle Database XE 21c on CentOS7. I am traversing all the nested elements of JSON data with the procedure shown below. However when I get the value of a number, the number loses its original format. For example, instead of getting 100.0, I get 100. How can I reserve the original format of the number? As you can see in my code below, I am using to_String to get value of the number. This is was one of my attempts to reserve the original number format. I have also tried with TO_CHAR & TO_NUMBER() . All give the same output. Your help is really appreciated.
Procedure Code
create or replace PROCEDURE ETA_JSON_SERIALIZE (
json_in IN JSON_ELEMENT_T,
can_str IN OUT VARCHAR2,
object_key IN VARCHAR2 DEFAULT NULL
)
IS
BEGIN
IF json_in.is_Object() THEN
DECLARE
l_object JSON_OBJECT_T := TREAT(json_in AS JSON_OBJECT_T);
l_keys JSON_KEY_LIST := l_object.get_Keys();
BEGIN
FOR i IN 1 .. l_keys.COUNT LOOP
can_str := can_str || '"'||UPPER(l_keys(i))||'"';
ETA_JSON_SERIALIZE(l_object.get(l_keys(i)), can_str, l_keys(i));
END LOOP;
END;
ELSIF json_in.is_Array() THEN
DECLARE
l_array JSON_ARRAY_T := TREAT(json_in AS JSON_ARRAY_T);
BEGIN
FOR i IN 0 .. l_array.get_size - 1 LOOP
IF object_key IS NOT NULL THEN
can_str := can_str || '"'||UPPER(object_key)||'"';
END IF;
ETA_JSON_SERIALIZE(l_array.get(i), can_str);
END LOOP;
END;
ELSIF json_in.is_Scalar() THEN
IF json_in.is_String() THEN
can_str := can_str || json_in.to_String();
ELSIF json_in.is_Number() THEN
can_str := can_str || '"' || TO_NUMBER(json_in.to_String) || '"';
END IF;
END IF;
END;
Sample Code - PL/SQL Block
SET SERVEROUTPUT ON
DECLARE
can_str VARCHAR2(32767);
l_doc CLOB := '{
"issuer": {
"address": {
"branchID": "1",
"country": "EG",
"governate": "Cairo",
"regionCity": "Nasr City",
"street": "580 Clementina Key",
"buildingNumber": "Bldg. 0",
"postalCode": "68030",
"floor": "1",
"room": "123",
"landmark": "7660 Melody Trail",
"additionalInformation": "beside Townhall"
},
"type": "B",
"id": "113317713",
"name": "Issuer Company"
},
"receiver": {
"address": {
"country": "EG",
"governate": "Egypt",
"regionCity": "Mufazat al Ismlyah",
"street": "580 Clementina Key",
"buildingNumber": "Bldg. 0",
"postalCode": "68030",
"floor": "1",
"room": "123",
"landmark": "7660 Melody Trail",
"additionalInformation": "beside Townhall"
},
"type": "B",
"id": "313717919",
"name": "Receiver"
},
"documentType": "I",
"documentTypeVersion": "0.9",
"dateTimeIssued": "2020-10-27T23:59:59Z",
"taxpayerActivityCode": "4620",
"internalID": "IID1",
"purchaseOrderReference": "P-233-A6375",
"purchaseOrderDescription": "purchase Order description",
"salesOrderReference": "1231",
"salesOrderDescription": "Sales Order description",
"proformaInvoiceNumber": "SomeValue",
"payment": {
"bankName": "SomeValue",
"bankAddress": "SomeValue",
"bankAccountNo": "SomeValue",
"bankAccountIBAN": "",
"swiftCode": "",
"terms": "SomeValue"
},
"delivery": {
"approach": "SomeValue",
"packaging": "SomeValue",
"dateValidity": "2020-09-28T09:30:10Z",
"exportPort": "SomeValue",
"countryOfOrigin": "EG",
"grossWeight": 10.50,
"netWeight": 20.50,
"terms": "SomeValue"
},
"invoiceLines": [
{
"description": "Computer1",
"itemType": "GPC",
"itemCode": "10001774",
"unitType": "EA",
"quantity": 5,
"internalCode": "IC0",
"salesTotal": 947.00,
"total": 2969.89,
"valueDifference": 7.00,
"totalTaxableFees": 817.42,
"netTotal": 880.71,
"itemsDiscount": 5.00,
"unitValue": {
"currencySold": "EUR",
"amountEGP": 189.40,
"amountSold": 10.00,
"currencyExchangeRate": 18.94
},
"discount": {
"rate": 7,
"amount": 66.29
},
"taxableItems": [
{
"taxType": "T1",
"amount": 272.07,
"subType": "T1",
"rate": 14.00
},
{
"taxType": "T2",
"amount": 208.22,
"subType": "T2",
"rate": 12
},
{
"taxType": "T3",
"amount": 30.00,
"subType": "T3",
"rate": 0.00
},
{
"taxType": "T4",
"amount": 43.79,
"subType": "T4",
"rate": 5.00
},
{
"taxType": "T5",
"amount": 123.30,
"subType": "T5",
"rate": 14.00
},
{
"taxType": "T6",
"amount": 60.00,
"subType": "T6",
"rate": 0.00
},
{
"taxType": "T7",
"amount": 88.07,
"subType": "T7",
"rate": 10.00
},
{
"taxType": "T8",
"amount": 123.30,
"subType": "T8",
"rate": 14.00
},
{
"taxType": "T9",
"amount": 105.69,
"subType": "T9",
"rate": 12.00
},
{
"taxType": "T10",
"amount": 88.07,
"subType": "T10",
"rate": 10.00
},
{
"taxType": "T11",
"amount": 123.30,
"subType": "T11",
"rate": 14.00
},
{
"taxType": "T12",
"amount": 105.69,
"subType": "T12",
"rate": 12.00
},
{
"taxType": "T13",
"amount": 88.07,
"subType": "T13",
"rate": 10.00
},
{
"taxType": "T14",
"amount": 123.30,
"subType": "T14",
"rate": 14.00
},
{
"taxType": "T15",
"amount": 105.69,
"subType": "T15",
"rate": 12.00
},
{
"taxType": "T16",
"amount": 88.07,
"subType": "T16",
"rate": 10.00
},
{
"taxType": "T17",
"amount": 88.07,
"subType": "T17",
"rate": 10.00
},
{
"taxType": "T18",
"amount": 123.30,
"subType": "T18",
"rate": 14.00
},
{
"taxType": "T19",
"amount": 105.69,
"subType": "T19",
"rate": 12.00
},
{
"taxType": "T20",
"amount": 88.07,
"subType": "T20",
"rate": 10.00
}
]
},
{
"description": "Computer2",
"itemType": "GPC",
"itemCode": "10003752",
"unitType": "EA",
"quantity": 7,
"internalCode": "IC0",
"salesTotal": 662.90,
"total": 2226.61,
"valueDifference": 6.00,
"totalTaxableFees": 621.51,
"netTotal": 652.90,
"itemsDiscount": 9.00,
"unitValue": {
"currencySold": "EUR",
"amountEGP": 94.70,
"amountSold": 5.00,
"currencyExchangeRate": 18.94
},
"discount": {
"rate": 0,
"amount": 10.00
},
"taxableItems": [
{
"taxType": "T1",
"amount": 205.47,
"subType": "T1",
"rate": 14.00
},
{
"taxType": "T2",
"amount": 157.25,
"subType": "T2",
"rate": 12
},
{
"taxType": "T3",
"amount": 30.00,
"subType": "T3",
"rate": 0.00
},
{
"taxType": "T4",
"amount": 32.20,
"subType": "T4",
"rate": 5.00
},
{
"taxType": "T5",
"amount": 91.41,
"subType": "T5",
"rate": 14.00
},
{
"taxType": "T6",
"amount": 60.00,
"subType": "T6",
"rate": 0.00
},
{
"taxType": "T7",
"amount": 65.29,
"subType": "T7",
"rate": 10.00
},
{
"taxType": "T8",
"amount": 91.41,
"subType": "T8",
"rate": 14.00
},
{
"taxType": "T9",
"amount": 78.35,
"subType": "T9",
"rate": 12.00
},
{
"taxType": "T10",
"amount": 65.29,
"subType": "T10",
"rate": 10.00
},
{
"taxType": "T11",
"amount": 91.41,
"subType": "T11",
"rate": 14.00
},
{
"taxType": "T12",
"amount": 78.35,
"subType": "T12",
"rate": 12.00
},
{
"taxType": "T13",
"amount": 65.29,
"subType": "T13",
"rate": 10.00
},
{
"taxType": "T14",
"amount": 91.41,
"subType": "T14",
"rate": 14.00
},
{
"taxType": "T15",
"amount": 78.35,
"subType": "T15",
"rate": 12.00
},
{
"taxType": "T16",
"amount": 65.29,
"subType": "T16",
"rate": 10.00
},
{
"taxType": "T17",
"amount": 65.29,
"subType": "T17",
"rate": 10.00
},
{
"taxType": "T18",
"amount": 91.41,
"subType": "T18",
"rate": 14.00
},
{
"taxType": "T19",
"amount": 78.35,
"subType": "T19",
"rate": 12.00
},
{
"taxType": "T20",
"amount": 65.29,
"subType": "T20",
"rate": 10.00
}
]
}
],
"totalDiscountAmount": 76.29,
"totalSalesAmount": 1609.90,
"netAmount": 1533.61,
"taxTotals": [
{
"taxType": "T1",
"amount": 477.54
},
{
"taxType": "T2",
"amount": 365.47
},
{
"taxType": "T3",
"amount": 60.00
},
{
"taxType": "T4",
"amount": 75.99
},
{
"taxType": "T5",
"amount": 214.71
},
{
"taxType": "T6",
"amount": 120.00
},
{
"taxType": "T7",
"amount": 153.36
},
{
"taxType": "T8",
"amount": 214.71
},
{
"taxType": "T9",
"amount": 184.04
},
{
"taxType": "T10",
"amount": 153.36
},
{
"taxType": "T11",
"amount": 214.71
},
{
"taxType": "T12",
"amount": 184.04
},
{
"taxType": "T13",
"amount": 153.36
},
{
"taxType": "T14",
"amount": 214.71
},
{
"taxType": "T15",
"amount": 184.04
},
{
"taxType": "T16",
"amount": 153.36
},
{
"taxType": "T17",
"amount": 153.36
},
{
"taxType": "T18",
"amount": 214.71
},
{
"taxType": "T19",
"amount": 184.04
},
{
"taxType": "T20",
"amount": 153.36
}
],
"totalAmount": 5191.50,
"extraDiscountAmount": 5.00,
"totalItemsDiscountAmount": 14.00
}';
BEGIN
ETA_JSON_SERIALIZE(JSON_ELEMENT_T.parse( l_doc ), can_str);
DBMS_OUTPUT.PUT_LINE(can_str);
END;
/
Output
"ISSUER""ADDRESS""BRANCHID""1""COUNTRY""EG""GOVERNATE""Cairo""REGIONCITY""Nasr City""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""113317713""NAME""Issuer Company""RECEIVER""ADDRESS""COUNTRY""EG""GOVERNATE""Egypt""REGIONCITY""Mufazat al Ismlyah""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""313717919""NAME""Receiver""DOCUMENTTYPE""I""DOCUMENTTYPEVERSION""0.9""DATETIMEISSUED""2020-10-27T23:59:59Z""TAXPAYERACTIVITYCODE""4620""INTERNALID""IID1""PURCHASEORDERREFERENCE""P-233-A6375""PURCHASEORDERDESCRIPTION""purchase Order description""SALESORDERREFERENCE""1231""SALESORDERDESCRIPTION""Sales Order description""PROFORMAINVOICENUMBER""SomeValue""PAYMENT""BANKNAME""SomeValue""BANKADDRESS""SomeValue""BANKACCOUNTNO""SomeValue""BANKACCOUNTIBAN""""SWIFTCODE""""TERMS""SomeValue""DELIVERY""APPROACH""SomeValue""PACKAGING""SomeValue""DATEVALIDITY""2020-09-28T09:30:10Z""EXPORTPORT""SomeValue""COUNTRYOFORIGIN""EG""GROSSWEIGHT""10.5""NETWEIGHT""20.5""TERMS""SomeValue""INVOICELINES""INVOICELINES""DESCRIPTION""Computer1""ITEMTYPE""GPC""ITEMCODE""10001774""UNITTYPE""EA""QUANTITY""5""INTERNALCODE""IC0""SALESTOTAL""947""TOTAL""2969.89""VALUEDIFFERENCE""7""TOTALTAXABLEFEES""817.42""NETTOTAL""880.71""ITEMSDISCOUNT""5""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""189.4""AMOUNTSOLD""10""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""7""AMOUNT""66.29""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""272.07""SUBTYPE""T1""RATE""14""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""208.22""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30""SUBTYPE""T3""RATE""0""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""43.79""SUBTYPE""T4""RATE""5""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""123.3""SUBTYPE""T5""RATE""14""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60""SUBTYPE""T6""RATE""0""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""88.07""SUBTYPE""T7""RATE""10""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""123.3""SUBTYPE""T8""RATE""14""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""105.69""SUBTYPE""T9""RATE""12""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""88.07""SUBTYPE""T10""RATE""10""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""123.3""SUBTYPE""T11""RATE""14""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""105.69""SUBTYPE""T12""RATE""12""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""88.07""SUBTYPE""T13""RATE""10""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""123.3""SUBTYPE""T14""RATE""14""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""105.69""SUBTYPE""T15""RATE""12""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""88.07""SUBTYPE""T16""RATE""10""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""88.07""SUBTYPE""T17""RATE""10""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""123.3""SUBTYPE""T18""RATE""14""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""105.69""SUBTYPE""T19""RATE""12""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""88.07""SUBTYPE""T20""RATE""10""INVOICELINES""DESCRIPTION""Computer2""ITEMTYPE""GPC""ITEMCODE""10003752""UNITTYPE""EA""QUANTITY""7""INTERNALCODE""IC0""SALESTOTAL""662.9""TOTAL""2226.61""VALUEDIFFERENCE""6""TOTALTAXABLEFEES""621.51""NETTOTAL""652.9""ITEMSDISCOUNT""9""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""94.7""AMOUNTSOLD""5""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""0""AMOUNT""10""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""205.47""SUBTYPE""T1""RATE""14""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""157.25""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30""SUBTYPE""T3""RATE""0""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""32.2""SUBTYPE""T4""RATE""5""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""91.41""SUBTYPE""T5""RATE""14""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60""SUBTYPE""T6""RATE""0""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""65.29""SUBTYPE""T7""RATE""10""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""91.41""SUBTYPE""T8""RATE""14""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""78.35""SUBTYPE""T9""RATE""12""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""65.29""SUBTYPE""T10""RATE""10""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""91.41""SUBTYPE""T11""RATE""14""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""78.35""SUBTYPE""T12""RATE""12""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""65.29""SUBTYPE""T13""RATE""10""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""91.41""SUBTYPE""T14""RATE""14""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""78.35""SUBTYPE""T15""RATE""12""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""65.29""SUBTYPE""T16""RATE""10""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""65.29""SUBTYPE""T17""RATE""10""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""91.41""SUBTYPE""T18""RATE""14""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""78.35""SUBTYPE""T19""RATE""12""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""65.29""SUBTYPE""T20""RATE""10""TOTALDISCOUNTAMOUNT""76.29""TOTALSALESAMOUNT""1609.9""NETAMOUNT""1533.61""TAXTOTALS""TAXTOTALS""TAXTYPE""T1""AMOUNT""477.54""TAXTOTALS""TAXTYPE""T2""AMOUNT""365.47""TAXTOTALS""TAXTYPE""T3""AMOUNT""60""TAXTOTALS""TAXTYPE""T4""AMOUNT""75.99""TAXTOTALS""TAXTYPE""T5""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T6""AMOUNT""120""TAXTOTALS""TAXTYPE""T7""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T8""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T9""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T10""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T11""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T12""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T13""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T14""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T15""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T16""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T17""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T18""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T19""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T20""AMOUNT""153.36""TOTALAMOUNT""5191.5""EXTRADISCOUNTAMOUNT""5""TOTALITEMSDISCOUNTAMOUNT""14"
Output Instances
How to make it reserve the original number format?
So "EXTRADISCOUNTAMOUNT""5.00"instead of"EXTRADISCOUNTAMOUNT""5"`
OR
"NETWEIGHT""20.50" instead of "NETWEIGHT""20.5"
OR
"TOTALITEMSDISCOUNTAMOUNT""14.00" instead of "TOTALITEMSDISCOUNTAMOUNT""14"
OR
"RATE""0.00" instead of "RATE""0"
You cannot.
Once you have parsed the JSON then Oracle has converted it to JSON_ELEMENT_T then there is no documented method that allows you to extract the underlying JSON text for that element so you can only use the serialization methods:
Serialization
Serialization is the inverse of the parse function. The serialization operation takes the in-memory representation of the JSON data and prints it to a string. The serialization functions and procedures are:
MEMBER FUNCTION to_String RETURN VARCHAR2
MEMBER FUNCTION to_Number RETURN NUMBER
MEMBER FUNCTION to_Date RETURN DATE
MEMBER FUNCTION to_Timestamp RETURN TIMESTAMP
MEMBER FUNCTION to_Boolean RETURN BOOLEAN
MEMBER FUNCTION to_Clob RETURN CLOB
MEMBER FUNCTION to_Blob RETURN BLOB
MEMBER PROCEDURE to_Clob(c IN OUT CLOB)
MEMBER PROCEDURE to_Blob(c IN OUT BLOB)
As noted in the documentation, "The serialization operation takes the in-memory representation of the JSON data and ...". Therefore if the parser converts the JSON to a NUMBER data type then only a NUMBER value will be stored and the formatting of the original JSON text is NOT stored. Since 10.00 is exactly the same value as 10 and a NUMBER does not store formatting then you can only retrieve the value 10 and not 10.00.
If you want to get the original text then you will have to use a different parser that lets you extract the underlying JSON text.
Alternatively, if all the numbers want to be formatted to 2 decimal places then you could use:
can_str := can_str || '"' || TO_CHAR(json_in.to_Number(), 'FM9999990D00') || '"';
fiddle
Did you try this?
ELSIF json_in.is_Scalar() THEN
IF json_in.is_String() THEN
can_str := can_str || json_in.to_String();
ELSIF json_in.is_Number() THEN
can_str := can_str ||'"'|| json_in.to_String()||'"';
END IF;
END IF;
Procedure:
`create or replace PROCEDURE ETA_JSON_SERIALIZE (
json_in IN JSON_ELEMENT_T,
can_str IN OUT VARCHAR2,
object_key IN VARCHAR2 DEFAULT NULL
)
IS
BEGIN
IF json_in.is_Object() THEN
DECLARE
l_object JSON_OBJECT_T := TREAT(json_in AS JSON_OBJECT_T);
l_keys JSON_KEY_LIST := l_object.get_Keys();
BEGIN
FOR i IN 1 .. l_keys.COUNT LOOP
can_str := can_str || '"'||UPPER(l_keys(i))||'"';
ETA_JSON_SERIALIZE(l_object.get(l_keys(i)), can_str,
l_keys(i));
END LOOP;
END;
ELSIF json_in.is_Array() THEN
DECLARE
l_array JSON_ARRAY_T := TREAT(json_in AS JSON_ARRAY_T);
BEGIN
FOR i IN 0 .. l_array.get_size - 1 LOOP
IF object_key IS NOT NULL THEN
can_str := can_str || '"'||UPPER(object_key)||'"';
END IF;
ETA_JSON_SERIALIZE(l_array.get(i), can_str);
END LOOP;
END;
ELSIF json_in.is_Scalar() THEN
IF json_in.is_String() THEN
can_str := can_str || json_in.to_String();
ELSIF json_in.is_Number() THEN
can_str := can_str ||'"'|| json_in.to_String()||'"';
END IF;
END IF;`
Output
"ISSUER""ADDRESS""BRANCHID""1""COUNTRY""EG""GOVERNATE""Cairo""REGIONCITY""Nasr City""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""113317713""NAME""Issuer Company""RECEIVER""ADDRESS""COUNTRY""EG""GOVERNATE""Egypt""REGIONCITY""Mufazat al Ismlyah""STREET""580 Clementina Key""BUILDINGNUMBER""Bldg. 0""POSTALCODE""68030""FLOOR""1""ROOM""123""LANDMARK""7660 Melody Trail""ADDITIONALINFORMATION""beside Townhall""TYPE""B""ID""313717919""NAME""Receiver""DOCUMENTTYPE""I""DOCUMENTTYPEVERSION""0.9""DATETIMEISSUED""2020-10-27T23:59:59Z""TAXPAYERACTIVITYCODE""4620""INTERNALID""IID1""PURCHASEORDERREFERENCE""P-233-A6375""PURCHASEORDERDESCRIPTION""purchase Order description""SALESORDERREFERENCE""1231""SALESORDERDESCRIPTION""Sales Order description""PROFORMAINVOICENUMBER""SomeValue""PAYMENT""BANKNAME""SomeValue""BANKADDRESS""SomeValue""BANKACCOUNTNO""SomeValue""BANKACCOUNTIBAN""""SWIFTCODE""""TERMS""SomeValue""DELIVERY""APPROACH""SomeValue""PACKAGING""SomeValue""DATEVALIDITY""2020-09-28T09:30:10Z""EXPORTPORT""SomeValue""COUNTRYOFORIGIN""EG""GROSSWEIGHT""10.50""NETWEIGHT""20.50""TERMS""SomeValue""INVOICELINES""INVOICELINES""DESCRIPTION""Computer1""ITEMTYPE""GPC""ITEMCODE""10001774""UNITTYPE""EA""QUANTITY""5""INTERNALCODE""IC0""SALESTOTAL""947.00""TOTAL""2969.89""VALUEDIFFERENCE""7.00""TOTALTAXABLEFEES""817.42""NETTOTAL""880.71""ITEMSDISCOUNT""5.00""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""189.40""AMOUNTSOLD""10.00""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""7""AMOUNT""66.29""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""272.07""SUBTYPE""T1""RATE""14.00""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""208.22""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30.00""SUBTYPE""T3""RATE""0.00""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""43.79""SUBTYPE""T4""RATE""5.00""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""123.30""SUBTYPE""T5""RATE""14.00""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60.00""SUBTYPE""T6""RATE""0.00""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""88.07""SUBTYPE""T7""RATE""10.00""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""123.30""SUBTYPE""T8""RATE""14.00""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""105.69""SUBTYPE""T9""RATE""12.00""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""88.07""SUBTYPE""T10""RATE""10.00""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""123.30""SUBTYPE""T11""RATE""14.00""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""105.69""SUBTYPE""T12""RATE""12.00""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""88.07""SUBTYPE""T13""RATE""10.00""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""123.30""SUBTYPE""T14""RATE""14.00""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""105.69""SUBTYPE""T15""RATE""12.00""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""88.07""SUBTYPE""T16""RATE""10.00""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""88.07""SUBTYPE""T17""RATE""10.00""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""123.30""SUBTYPE""T18""RATE""14.00""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""105.69""SUBTYPE""T19""RATE""12.00""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""88.07""SUBTYPE""T20""RATE""10.00""INVOICELINES""DESCRIPTION""Computer2""ITEMTYPE""GPC""ITEMCODE""10003752""UNITTYPE""EA""QUANTITY""7""INTERNALCODE""IC0""SALESTOTAL""662.90""TOTAL""2226.61""VALUEDIFFERENCE""6.00""TOTALTAXABLEFEES""621.51""NETTOTAL""652.90""ITEMSDISCOUNT""9.00""UNITVALUE""CURRENCYSOLD""EUR""AMOUNTEGP""94.70""AMOUNTSOLD""5.00""CURRENCYEXCHANGERATE""18.94""DISCOUNT""RATE""0""AMOUNT""10.00""TAXABLEITEMS""TAXABLEITEMS""TAXTYPE""T1""AMOUNT""205.47""SUBTYPE""T1""RATE""14.00""TAXABLEITEMS""TAXTYPE""T2""AMOUNT""157.25""SUBTYPE""T2""RATE""12""TAXABLEITEMS""TAXTYPE""T3""AMOUNT""30.00""SUBTYPE""T3""RATE""0.00""TAXABLEITEMS""TAXTYPE""T4""AMOUNT""32.20""SUBTYPE""T4""RATE""5.00""TAXABLEITEMS""TAXTYPE""T5""AMOUNT""91.41""SUBTYPE""T5""RATE""14.00""TAXABLEITEMS""TAXTYPE""T6""AMOUNT""60.00""SUBTYPE""T6""RATE""0.00""TAXABLEITEMS""TAXTYPE""T7""AMOUNT""65.29""SUBTYPE""T7""RATE""10.00""TAXABLEITEMS""TAXTYPE""T8""AMOUNT""91.41""SUBTYPE""T8""RATE""14.00""TAXABLEITEMS""TAXTYPE""T9""AMOUNT""78.35""SUBTYPE""T9""RATE""12.00""TAXABLEITEMS""TAXTYPE""T10""AMOUNT""65.29""SUBTYPE""T10""RATE""10.00""TAXABLEITEMS""TAXTYPE""T11""AMOUNT""91.41""SUBTYPE""T11""RATE""14.00""TAXABLEITEMS""TAXTYPE""T12""AMOUNT""78.35""SUBTYPE""T12""RATE""12.00""TAXABLEITEMS""TAXTYPE""T13""AMOUNT""65.29""SUBTYPE""T13""RATE""10.00""TAXABLEITEMS""TAXTYPE""T14""AMOUNT""91.41""SUBTYPE""T14""RATE""14.00""TAXABLEITEMS""TAXTYPE""T15""AMOUNT""78.35""SUBTYPE""T15""RATE""12.00""TAXABLEITEMS""TAXTYPE""T16""AMOUNT""65.29""SUBTYPE""T16""RATE""10.00""TAXABLEITEMS""TAXTYPE""T17""AMOUNT""65.29""SUBTYPE""T17""RATE""10.00""TAXABLEITEMS""TAXTYPE""T18""AMOUNT""91.41""SUBTYPE""T18""RATE""14.00""TAXABLEITEMS""TAXTYPE""T19""AMOUNT""78.35""SUBTYPE""T19""RATE""12.00""TAXABLEITEMS""TAXTYPE""T20""AMOUNT""65.29""SUBTYPE""T20""RATE""10.00""TOTALDISCOUNTAMOUNT""76.29""TOTALSALESAMOUNT""1609.90""NETAMOUNT""1533.61""TAXTOTALS""TAXTOTALS""TAXTYPE""T1""AMOUNT""477.54""TAXTOTALS""TAXTYPE""T2""AMOUNT""365.47""TAXTOTALS""TAXTYPE""T3""AMOUNT""60.00""TAXTOTALS""TAXTYPE""T4""AMOUNT""75.99""TAXTOTALS""TAXTYPE""T5""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T6""AMOUNT""120.00""TAXTOTALS""TAXTYPE""T7""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T8""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T9""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T10""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T11""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T12""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T13""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T14""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T15""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T16""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T17""AMOUNT""153.36""TAXTOTALS""TAXTYPE""T18""AMOUNT""214.71""TAXTOTALS""TAXTYPE""T19""AMOUNT""184.04""TAXTOTALS""TAXTYPE""T20""AMOUNT""153.36""TOTALAMOUNT""5191.50""EXTRADISCOUNTAMOUNT""5.00""TOTALITEMSDISCOUNTAMOUNT""14.00"
Is there a way to pass a value or variable into json_path in Mysql?
I am trying to use json_table to get value from the header of my json and then get date in my content from the index that i got.
In my code below, i am trying to passe the value jsh.cName
My query
Select jsh.cName, jsc.qteRecu from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId IN (
Select df.documentId from
DocumentField as df inner join DocumentAnchor DA on DA.currentDocId = df.documentId
inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 135 AND df.calcValue = "13476148-0" -- $135$
) inner join tpl_fields TF on TF.id = df.fieldId and TF.fieldId = 143 AND JSON_VALID(df.calcValue)
inner join Template on Template.id = DA.templateId AND Template.TypeTemplate_id = 6 -- bordereau de livraison
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.header[*]"
COLUMNS(
cId INT path '$."globalColumnId"',
cName VARCHAR(256) PATH '$."name"')
) as jsh ON jsh.cId = 8
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
qteRecu VARCHAR(256) PATH "$.MY_DATE_HERE(jsh.cName)")
) as jsc
WHERE jsc.qteRecu != "" AND jsc.qteRecu IS NOT NULL;
My json, there is the header where i got the name of the key and content is where i'am trying to get the value from the key name :
"header": [
{
"id": 1026,
"name": "No projet",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1226,
"y1": 627,
"x2": 1276,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-14 15:29:39",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": null,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 25,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1016,
"name": "No ligne",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 1,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1278,
"y1": 627,
"x2": 1328,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 1,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1017,
"name": "Article",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1330,
"y1": 627,
"x2": 1380,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 11,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1018,
"name": "Qte re\u00e7ue",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1382,
"y1": 627,
"x2": 1432,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 8,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1019,
"name": "Prix PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 50,
"height": 238,
"x1": 1434,
"y1": 627,
"x2": 1484,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 3,
"isDummy": 0,
"globalColumnId": 30,
"listDataId": null,
"zoneTolerence": null
},
{
"id": 1020,
"name": "Compte GL PO",
"templateId": 213,
"tpl_fieldId": 3374,
"pageId": 0,
"isLineDefiner": 0,
"startValue": "",
"mandatoryStartValue": 0,
"stopValue": "",
"mandatoryStopValue": 0,
"defaultValue": "",
"width": 117,
"height": 238,
"x1": 1486,
"y1": 627,
"x2": 1603,
"y2": 864,
"ocrConfTolerance": 65,
"zoneTolerencePix": null,
"mask": null,
"created": "2021-06-09 13:44:33",
"createdBy": 1,
"modified": "2021-06-14 15:29:39",
"modifiedBy": 1,
"disabled": 0,
"noSpace": 0,
"typeId": 0,
"isDummy": 0,
"globalColumnId": 33,
"listDataId": null,
"zoneTolerence": null
}
],
"content": [
{
"No projet": "0",
"No ligne": 1,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
},
{
"No projet": "15CALL",
"No ligne": 2,
"Article": "275019734",
"Qte re\u00e7ue": 1,
"Prix PO": 20,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "15CALL",
"No ligne": 3,
"Article": "217041984",
"Qte re\u00e7ue": 1,
"Prix PO": 135,
"Compte GL PO": "570010;570010;110499"
},
{
"No projet": "0",
"No ligne": 4,
"Article": "",
"Qte re\u00e7ue": "",
"Prix PO": 0,
"Compte GL PO": ""
}
]
I don't think that's possible. The PATH must be fixed before you join to other tables. So there's no way to make the PATH different based on values in other tables you join to.
This is similar to questions where folks want to join to a different table or a different column per row. SQL does not support that. The tables and columns must be fixed before the query begins reading any rows of data or evaluating expressions.
Instead, I recommend to expose all the content fields using separate paths, and then use a CASE expression to pick one:
SELECT jsh.cName, CASE jsh.cName
WHEN 'No projet' THEN jsc.NoProjet
WHEN 'No ligne' THEN jsc.NoLigne
WHEN 'Article' THEN jsc.Article
...
END AS qteRecu
FROM ...
CROSS JOIN JSON_TABLE(
JSON_UNQUOTE(df.calcValue), "$.content[*]"
COLUMNS(
NoProjet VARCHAR(256) PATH '$."No projet"',
NoLigne INT PATH '$."No ligne"',
Article VARCHAR(256) PATH '$.Article',
QteRecu VARCHAR(256) PATH '$."Qte re\u00e7ue"',
...)
) as jsc
Another alternative is to structure your content as a different JSON document.
I'm trying to get this to validate, it's probably a comma or formatting but I can't work it out and it's driving me insane - It doesn't seem to fail initially not sure why it does later on.
For reference: https://umod.org/plugins/server-rewards#adding-an-item
Any help would be appreciated - Thanks in advance.
{
"items": {
"lmg.m249_0": {
"shortname": "lmg.m249",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "M249",
"cost": 100,
"cooldown": 0
},
"rifle.l96_0": {
"shortname": "rifle.l96",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "L96 Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.m39_0": {
"shortname": "rifle.m39",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "M39 Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.lr300_0": {
"shortname": "rifle.lr300",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "LR-300 Assault Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.ak_0": {
"shortname": "rifle.ak",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Assault Rifle",
"cost": 100,
"cooldown": 0
},
"pistol.python_0": {
"shortname": "pistol.python",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Python Revolver",
"cost": 100,
"cooldown": 0
},
"rocket.launcher_0": {
"shortname": "rocket.launcher",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Rocket Launcher",
"cost": 100,
"cooldown": 0
},
"multiplegrenadelauncher_0": {
"shortname": "multiplegrenadelauncher",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Multiple Grenade Launcher",
"cost": 100,
"cooldown": 0
},
"weapon.mod.lasersight_0": {
"shortname": "weapon.mod.lasersight",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Weapon Lasersight",
"cost": 100,
"cooldown": 0
},
"weapon.mod.silencer_0": {
"shortname": "weapon.mod.silencer",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Silencer",
"cost": 100,
"cooldown": 0
},
"ammo.rifle_0": {
"shortname": "ammo.rifle",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rifle.hv_0": {
"shortname": "ammo.rifle.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "HV 5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rifle.explosive_0": {
"shortname": "ammo.rifle.explosive",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Explosive 5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.shotgun_0: {
"shortname": "ammo.shotgun",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "12 Gauge Buckshot",
"cost": 100,
"cooldown": 0
},
"ammo.shotgun.slug_0": {
"shortname": "ammo.shotgun.slug",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "12 Gauge Slug",
"cost": 100,
"cooldown": 0
},
"ammo.pistol_0": {
"shortname": "ammo.pistol",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Pistol Bullet",
"cost": 100,
"cooldown": 0
},
"ammo.pistol.hv_0": {
"shortname": "ammo.pistol.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "HV Pistol Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.basic_0": {
"shortname": "ammo.rocket.basic",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Rocket",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.hv_0": {
"shortname": "ammo.rocket.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "High Velocity Rocket",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.sam_0": {
"shortname": "ammo.rocket.sam",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "SAM Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.grenadelauncher.he_0": {
"shortname": "ammo.grenadelauncher.he",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "40mm HE Grenade",
"cost": 100,
"cooldown": 0
},
"ammo.grenadelauncher.buckshot_0": {
"shortname": "ammo.grenadelauncher.buckshot",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "40mm Shotgun Round",
"cost": 100,
"cooldown": 0
}
},
"kits": {},
"commands": {}
}
The error was the extra } above "kits".
{
"items": {
"lmg.m249_0": {
"shortname": "lmg.m249",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "M249",
"cost": 100,
"cooldown": 0
},
"rifle.l96_0": {
"shortname": "rifle.l96",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "L96 Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.m39_0": {
"shortname": "rifle.m39",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "M39 Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.lr300_0": {
"shortname": "rifle.lr300",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "LR-300 Assault Rifle",
"cost": 100,
"cooldown": 0
},
"rifle.ak_0": {
"shortname": "rifle.ak",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Assault Rifle",
"cost": 100,
"cooldown": 0
},
"pistol.python_0": {
"shortname": "pistol.python",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Python Revolver",
"cost": 100,
"cooldown": 0
},
"rocket.launcher_0": {
"shortname": "rocket.launcher",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Rocket Launcher",
"cost": 100,
"cooldown": 0
},
"multiplegrenadelauncher_0": {
"shortname": "multiplegrenadelauncher",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Multiple Grenade Launcher",
"cost": 100,
"cooldown": 0
},
"weapon.mod.lasersight_0": {
"shortname": "weapon.mod.lasersight",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Weapon Lasersight",
"cost": 100,
"cooldown": 0
},
"weapon.mod.silencer_0": {
"shortname": "weapon.mod.silencer",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Silencer",
"cost": 100,
"cooldown": 0
},
"ammo.rifle_0": {
"shortname": "ammo.rifle",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rifle.hv_0": {
"shortname": "ammo.rifle.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "HV 5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rifle.explosive_0": {
"shortname": "ammo.rifle.explosive",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Explosive 5.56 Rifle Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.shotgun_0: {
"shortname": "ammo.shotgun",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "12 Gauge Buckshot",
"cost": 100,
"cooldown": 0
},
"ammo.shotgun.slug_0": {
"shortname": "ammo.shotgun.slug",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "12 Gauge Slug",
"cost": 100,
"cooldown": 0
},
"ammo.pistol_0": {
"shortname": "ammo.pistol",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Pistol Bullet",
"cost": 100,
"cooldown": 0
},
"ammo.pistol.hv_0": {
"shortname": "ammo.pistol.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "HV Pistol Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.basic_0": {
"shortname": "ammo.rocket.basic",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "Rocket",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.hv_0": {
"shortname": "ammo.rocket.hv",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "High Velocity Rocket",
"cost": 100,
"cooldown": 0
},
"ammo.rocket.sam_0": {
"shortname": "ammo.rocket.sam",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "SAM Ammo",
"cost": 100,
"cooldown": 0
},
"ammo.grenadelauncher.he_0": {
"shortname": "ammo.grenadelauncher.he",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "40mm HE Grenade",
"cost": 100,
"cooldown": 0
},
"ammo.grenadelauncher.buckshot_0": {
"shortname": "ammo.grenadelauncher.buckshot",
"customIcon": null,
"amount": 1,
"skinId": 0,
"isBp": false,
"category": 1,
"displayName": "40mm Shotgun Round",
"cost": 100,
"cooldown": 0
},
"kits": {},
"commands": {}
}
I'm trying to achieve table structure attached in the image :
Composite Class Routine
So far what I've tried can be seen in the following Plunker:
https://plnkr.co/edit/4WiWKDIM2bNfnmRjFo91?p=preview
My json data is :
$scope.routines = [
{
"WEEKDAY_ID": 1,
"WEEKDAY": "Sunday",
"aSemester": [
{
"SEMESTER_ID": 1,
"SEMESTER_NAME": "1st",
"aClassTime": [
{
"COURSE_ID": 1,
"COURSE_CODE": "CSTE-1001",
"CLASS_DURATION": 3,
"CLASSTIME_ID": 1,
"CLASSTIME": "9.00-9.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-1",
"ROOM_NO": 101,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 10,
"INSTRUCTOR_NAME": "Abhijit Chakraborty",
"SHORT_CODE": "AC"
},
{
"COURSE_ID": 7,
"COURSE_CODE": "CSTE-1106",
"CLASS_DURATION": 1,
"CLASSTIME_ID": 4,
"CLASSTIME": "12.00-12.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-2",
"ROOM_NO": 258,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 10,
"INSTRUCTOR_NAME": "Abhijit Chakraborty",
"SHORT_CODE": "AC"
},
{
"COURSE_ID": 3,
"COURSE_CODE": "CSTE-1102",
"CLASS_DURATION": 1,
"CLASSTIME_ID": 7,
"CLASSTIME": "4.00-4.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-2",
"ROOM_NO": 252,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 9,
"INSTRUCTOR_NAME": "Dr. Md. Asadun Nabi",
"SHORT_CODE": "MAN"
}
]
},
{
"SEMESTER_ID": 2,
"SEMESTER_NAME": "2nd",
"aClassTime": [
{
"COURSE_ID": 7,
"COURSE_CODE": "CSTE-1106",
"CLASS_DURATION": 1,
"CLASSTIME_ID": 1,
"CLASSTIME": "9.00-9.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-4",
"ROOM_NO": 456,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 6,
"INSTRUCTOR_NAME": "Dr. Humayun Kabir",
"SHORT_CODE": "HK"
},
{
"COURSE_ID": 3,
"COURSE_CODE": "CSTE-1102",
"CLASS_DURATION": 1,
"CLASSTIME_ID": 2,
"CLASSTIME": "10.00-10.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-1",
"ROOM_NO": 102,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 6,
"INSTRUCTOR_NAME": "Dr. Humayun Kabir",
"SHORT_CODE": "HK"
}
]
},
{
"SEMESTER_ID": 3,
"SEMESTER_NAME": "3rd",
"aClassTime": [
{
"COURSE_ID": 5,
"COURSE_CODE": "CSTE-4202",
"CLASS_DURATION": 1,
"CLASSTIME_ID": 7,
"CLASSTIME": "4.00-4.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-2",
"ROOM_NO": 252,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 7,
"INSTRUCTOR_NAME": "Md. Javed Hossain",
"SHORT_CODE": "MJH"
}
]
},
{
"SEMESTER_ID": 4,
"SEMESTER_NAME": "4th",
"aClassTime": [
{
"COURSE_ID": 61,
"COURSE_CODE": "CSTE-2204",
"CLASS_DURATION": 2,
"CLASSTIME_ID": 1,
"CLASSTIME": "9.00-9.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-1",
"ROOM_NO": 404,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 6,
"INSTRUCTOR_NAME": "Dr. Humayun Kabir",
"SHORT_CODE": "HK"
},
{
"COURSE_ID": 62,
"COURSE_CODE": "CSTE-2206",
"CLASS_DURATION": 2,
"CLASSTIME_ID": 3,
"CLASSTIME": "11.00-11.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-1",
"ROOM_NO": 101,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 10,
"INSTRUCTOR_NAME": "Abhijit Chakraborty",
"SHORT_CODE": "AC"
},
{
"COURSE_ID": 63,
"COURSE_CODE": "CSTE-2202",
"CLASS_DURATION": 3,
"CLASSTIME_ID": 5,
"CLASSTIME": "2.00-2.50",
"DEPT_ID": 1,
"DEPT_NAME": "Computer Science",
"BUILDING_NAME": "Academic-3",
"ROOM_NO": 303,
"LAB_GROUP": null,
"INSTRUCTOR_ID": 7,
"INSTRUCTOR_NAME": "Md. Javed Hossain",
"SHORT_CODE": "MJH"
}
]
}
]
}
];
and html I tried so far is :
<table id="routines" class="table table-bordered table-responsive table-condensed">
<thead>
<tr>
<th>Day</th>
<th>Semester</th>
<th ng-repeat="c in classtimes">{{c.CLASSTIME}}</th>
</tr>
</thead>
<tbody ng-repeat="r in routines">
<tr ng-repeat="s in r.aSemester">
<td rowspan="{{r.aSemester.length}}">{{r.WEEKDAY}}</td>
<td>{{s.SEMESTER_NAME}}</td>
<td colspan={{c.CLASS_DURATION}}
ng-repeat="c in s.aClassTime">
{{c.COURSE_CODE}}
</td>
</tr>
</tbody>
any kind of help would be appreciated.
Replace your table body with this
<tbody>
<tr ng-repeat-start="r in routines">
<td rowspan="{{r.aSemester.length+1}}">{{r.WEEKDAY}}</td>
</tr>
<tr ng-repeat="aSem in r.aSemester">
<td>{{aSem.SEMESTER_NAME}}</td>
<td ng-repeat="c in classtimes">
<span ng-repeat="classTime in aSem.aClassTime">
<span ng-if="classTime.CLASSTIME_ID==c.CLASSTIME_ID">
{{classTime.COURSE_CODE}}
</span>
</span>
</td>
</tr>
<tr ng-repeat-end ></tr>
</tbody>
I think this should help.
Plunkr https://plnkr.co/edit/QFUouMmSKtBiAWMdGpCC?p=preview