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": {}
}
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
Hi I'm trying to retrieve values from a Nest Json Column of a table and sum them. Which look's like below,
ID Details Created_At
2345 2021-05-31
3243 2021-06-02
3243 2021-06-02
3243 2021-06-02
Here the 'Details' column is the one which has json values in it per row, in below format
{
"new_products": [
{
"bucket": "READY",
"sku": "46123445323423",
"overaged": 0,
"transfer": 0,
"total_count": 14,
"actual_count": 14,
"lock_quantity": 0
},
],
"old_products": [
{
"bucket": "READY",
"sku": "451902224524",
"overaged": 0,
"transfer": 0,
"total_count": 59,
"actual_count": 59,
"lock_quantity": 0
},
{
"bucket": "READY",
"sku": "46123445323423",
"overaged": 0,
"transfer": 0,
"total_count": 14,
"actual_count": 14,
"lock_quantity": 0
},
{
"bucket": "READY",
"sku": "42342361484",
"overaged": 0,
"transfer": 0,
"total_count": 29,
"actual_count": 29,
"lock_quantity": 0
},
{
"bucket": "READY",
"sku": "23234234342",
"overaged": 0,
"transfer": 0,
"total_count": 57,
"actual_count": 57,
"lock_quantity": 0
}
]
}
What i have been able to achieve in my query :
SELECT ID,
Created_At,
(json_extract(Details,'$.old_products') ) AS column
FROM Table)
This just extracts 'old_products' values in a new column,
But, I'm trying to sum all the values of total_count , actual_count from key 'old_products','new_products' of every row into a new column.
How can that be achieved?
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 have the following input with nested JSON, I want to ingest this data into hive in multiple rows
"taxes": [{
"line_id": 1,
"commodity_code": "997159",
"fee": {
"amt": {
"curr_code": "USD",
"value": "71.4"
},
"type": "receiver"
},
"ship_addr": {
"admin_area_1": "MAHARASHTRA",
"country_code": "IN"
},
"total_tax": {
"curr_code": "USD",
"value": "12.8520000000"
},
"tax-details": [{
"exempt_option": false,
"auth_name": "India Maharashtra Central GST",
"doc_amt": {
"currency_code": "USD",
"value": "6.43"
},
"unrnd_doc_amt": {
"currency_code": "USD",
"value": "6.4260000000"
},
"rate": "0.09",
"rate_code": "SR",
"non_basis_doc_amt": "0.00",
"exempt_doc_amt": "0.00",
"jdx_memo": "INSS2: Tax payable in Seller location.",
"seller_reg_no": "27AAGCP4442G1ZF",
"admin_zone_level": "Country",
"auth_type": "CGST",
"erp_code": "MHCGST",
"inv_desc": "Standard Rate - CGST",
"basis_doc_amt": "71.40"
}, {
"exempt_option": false,
"auth_name": "India Maharashtra State GST",
"doc_amt": {
"currency_code": "USD",
"value": "6.43"
},
"unrnd_doc_amt": {
"currency_code": "USD",
"value": "6.4260000000"
},
"rate": "0.09",
"rate_code": "SR",
"non_basis_doc_amt": "0.00",
"exempt_doc_amt": "0.00",
"jdx_memo": "INSS2: Tax payable in Seller location.",
"seller_reg_no": "27AAGCP4442G1ZF",
"admin_zone_level": "Province",
"auth_type": "SGST",
"erp_code": "MHSGST",
"inv_desc": "Standard Rate - SGST",
"basis_doc_amt": "71.40"
}],
"transaction_type": "DS"
}]
I am using the following DDL
select
get_json_object(t.json,concat('$.taxes[',e.i,'].line_id')) as line_id
, get_json_object(t.json,concat('$.taxes[',e.i,'].commodity_code')) as commodity_code
, get_json_object(t.json,concat('$.taxes[',e.i,'].fee.amt.curr_code')) as curr_code
, get_json_object(t.json,concat('$.taxes[',e.i,'].fee.amt.value')) as value
, get_json_object(t.json,concat('$.taxes[',e.i,'].fee.type')) as type
, get_json_object(t.json,concat('$.taxes[',e.i,'].ship_addr.admin_area_1')) as admin_area
, get_json_object(t.json,concat('$.taxes[',e.i,'].ship_addr.country_code')) as country_code
, get_json_object(t.json,concat('$.taxes[',e.i,'].total_tax.curr_code')) as total_tax_curr_code
, get_json_object(t.json,concat('$.taxes[',e.i,'].total_tax.value')) as total_tax_value
get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].exempt_option')) as exempt_option
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].auth_name')) as auth_name
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].doc_amt.currency_code')) as doc_amt_currency_code
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].doc_amt.value')) as doc_amt_value
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].unrnd_doc_amt.currency_code')) as unrnd_doc_amt_currency_code
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].unrnd_doc_amt.value')) as unrnd_doc_amt_value
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].rate')) as rate
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].rate_code')) as rate_code
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].non_basis_doc_amt')) as non_basis_doc_amt
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].exempt_doc_amt')) as exempt_doc_amount
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].jdx_memo')) as jdx_memo
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].seller_reg_no')) as seller_reg_no
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].admin_zone_level')) as admin_zone_level
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].auth_type')) as auth_type
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].erp_code')) as erp_code
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].inv_desc')) as inv_desc
, get_json_object(t.json,concat('$.taxes.tax_details[',f.g,'].basis_doc_amt')) as basis_doc_amt
FROM json_2002 t
LATERAL VIEW POSEXPLODE (split(get_json_object(json,'$.taxes[*].line_id'),'","')) e as i,x
LATERAL VIEW POSEXPLODE (split(get_json_object(json,'$taxes.tax_details[*].exempt_option'),'","')) f as g,h
I was able to fix the issue by using regex_replace
LATERAL VIEW POSEXPLODE (split(regexp_replace(get_json_object(json,'$.taxes.tax_details[*].exempt_option'), '\[|\]', ''), ',' ) ) f as g,h
solved my problem
how to correctly convert a Powershell array of object properties to a json array of values, that is without the objects property lables in the array.
for example:
I want to make 2 json arrays for chart.js
I will group some process objects:
$processgroup = get-process | group -property name
$processgroup.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
$chartlabels = $processgroup.name | convertto-json
$chartlabels
$chartlabels
[
"ApMsgFwd",
"ApntEx",
"Apoint",
"ApplicationFrameHost",
"armsvc",
"BtwRSupportService",
"chrome",
"com.docker.proxy",
"com.docker.service",
"concentr",
"conhost",
"csrss",
"dllhost",
"Docker for Windows",
"dockerd",
"dwm",
"Everything",
"EXCEL",
"explorer",
"fontdrvhost",
"GROOVE",
"hidfind",
"HidMonitorSvc",
"Idle",
"iexplore",
"IpOverUsbSvc",
"jucheck",
"jusched",
"LicensingUI",
"lsass",
"mDNSResponder",
"Memory Compression",
"mqsvc",
"MSASCuiL",
"MsMpEng",
"MSOIDSVC",
"MSOIDSVCM",
"MySQLNotifier",
"NisSrv",
"notepad",
"notepad++",
"nvSCPAPISvr",
"nvvsvc",
"nvwmi64",
"nvxdsync",
"OfficeClickToRun",
"OneDrive",
"OUTLOOK",
"powershell",
"powershell_ise",
"prevhost",
"Receiver",
"redirector",
"rundll32",
"RuntimeBroker",
"SearchIndexer",
"SearchUI",
"Secure System",
"SecurityHealthService",
"SelfServicePlugin",
"services",
"SettingSyncHost",
"ShellExperienceHost",
"sihost",
"SkypeHost",
"smss",
"SMSvcHost",
"spiceworks",
"spiceworks-httpd",
"spoolsv",
"SppExtComObj",
"sppsvc",
"sqlwriter",
"svchost",
"System",
"SystemSettings",
"taskhostw",
"TSVNCache",
"vmcompute",
"vmms",
"vmnat",
"vmnetdhcp",
"vmware-authd",
"vmware-tray",
"vmware-usbarbitrator64",
"wfcrun32",
"wininit",
"winlogon",
"WINWORD",
"WmiPrvSE",
"WUDFHost"
]
#this is the array I want for charts labels, now for the chart value array
$chartvalues = $processgroup | select count | convertto-json
$chartvalues
[
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 30
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 5
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 4
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 30
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 75
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 1
},
{
"Count": 2
},
{
"Count": 1
},
{
"Count": 1
}
]
how do I omit the "Count" label so PowerShell creates a single json array of the values only, as in the process name array.
I have tried
$chartvalues = $processgroup.count
results in the count of the number of groups
and I have tried
$chartvalues = $ processgroup | select count -expandproperty count | convertto-json
with the same result as above example
You want a list, rather than object with key/value pair, so this should work*:
$groups| foreach-object {$_.count}|convertto-json
When you do select after the pipeline it creates an object, thus pushes the object property name as well as the value as key/value pair into the json conversion process.
i.e. If you have used select for name property, you would get the name/value pair in the json too...
$groups| select-object name| convertto-json
*may be better solutions out there... but itworks..
Silly me - I only needed to select and expand the property. like so.
$chartvalues = $processgroup | select -expandproperty count | convertto-json
$chartvalues
[
1,
1,
1,
1,
1,
1,
30,
1,
1,
1,
5,
2,
1,
1,
1,
1,
2,
1,
1,
2,
1,
1,
1,
1,
4,
1,
1,
1,
30,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
1,
1,
2,
2,
1,
1,
1,
1,
1,
2,
1,
1,
1,
2,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
1,
2,
1,
1,
1,
1,
75,
1,
1,
1,
2,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
1,
1
]
All you have to do use the -ExpandProperty property of Select-Object to achieve your stated desire. Is there any reason not to preserve the property->value notation which association inside of a single JSON array? e.g.:
$processgroup = get-process | group -property name,count | select name,count | convertto-json
yields:
$processgroup
[
{
"Name": "acevents",
"Count": 1
},
{
"Name": "acrotray",
"Count": 1
},
{
"Name": "AGSService",
"Count": 1
},
{
"Name": "aiCOMMAPI",
"Count": 1
},
{
"Name": "armsvc",
"Count": 1
},
{
"Name": "audiodg",
"Count": 1
},
{
"Name": "AuditManagerService",
"Count": 1
},
{
"Name": "CcmExec",
"Count": 1
},
{
"Name": "chrome",
"Count": 9
},
{
"Name": "conhost",
"Count": 2
},
{
"Name": "csrss",
"Count": 2
},
{
"Name": "dllhost",
"Count": 2
},
{
"Name": "dwm",
"Count": 1
},
{
"Name": "explorer",
"Count": 1
},
{
"Name": "Idle",
"Count": 1
},
{
"Name": "lsass",
"Count": 1
},
{
"Name": "lync",
"Count": 1
},
{
"Name": "msdtc",
"Count": 1
}
]