DataFlex
DataFlex
ITIDA Create Canonical JSON
See more Egypt ITIDA Examples
Demonstrates creating the canonical (ITIDA) version of a JSON document. The document in the example is the one at https://sdk.invoicing.eta.gov.eg/files/one-doc.jsonNote: This example requires Chilkat v9.5.0.92 or greater.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSb
String sCanonical
Expected Handle hoSbExpected
Boolean bTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Note: This example requires Chilkat v9.5.0.92 or greater.
// (In v9.5.0.92, the "itida" encoding was added to StringBuilder's Encode method.)
Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
If (Not(IsComObjectCreated(hoSb))) Begin
Send CreateComObject of hoSb
End
// This is the file at https://sdk.invoicing.eta.gov.eg/files/one-doc.json
Get ComLoadFile Of hoSb "qa_data/itida/sdk.invoicing.eta.gov.eg/files/one-doc.json" "utf-8" To iSuccess
If (iSuccess = False) Begin
Showln "Failed to load input file."
Procedure_Return
End
// Convert the contents of sb to the ITIDA canonical form.
// Always pass utf-8 for the 2nd arg.
Get ComEncode Of hoSb "itida" "utf-8" To iSuccess
Get ComGetAsString Of hoSb To sCanonical
Showln sCanonical
// Output:
// "SomeValue""DELIVERY""APPROACH""SomeValue""PACKAGING""SomeValue""DATEVALIDITY""2020-09-28T09:30:10Z"........."TOTALAMOUNT""5191.50""EXTRADISCOUNTAMOUNT""5.00""TOTALITEMSDISCOUNTAMOUNT""14.00"
// Let's verify we got the correct result.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbExpected
If (Not(IsComObjectCreated(hoSbExpected))) Begin
Send CreateComObject of hoSbExpected
End
Get ComLoadFile Of hoSbExpected "qa_data/itida/sdk.invoicing.eta.gov.eg/files/one-doc-serialized.json.txt" "utf-8" To iSuccess
If (iSuccess = False) Begin
Showln "Failed to expected output file."
Procedure_Return
End
// Compare our computed canonical string with the expected result.
Get ComContentsEqualSb Of hoSb Get pvComObject of hoSbExpected to vSbExpected
vSbExpected True To bTemp1
If (bTemp1 = True) Begin
Showln "The computed canonical result is correct."
End
Else Begin
Showln "The computed canonical result is NOT correct."
End
End_Procedure