Sample code for 30+ languages & platforms
PowerBuilder

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.json

Note: This example requires Chilkat v9.5.0.92 or greater.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Sb
string ls_Canonical
oleobject loo_SbExpected

li_Success = 0

// 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.)
loo_Sb = create oleobject
li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_Sb
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// This is the file at https://sdk.invoicing.eta.gov.eg/files/one-doc.json
li_Success = loo_Sb.LoadFile("qa_data/itida/sdk.invoicing.eta.gov.eg/files/one-doc.json","utf-8")
if li_Success = 0 then
    Write-Debug "Failed to load input file."
    destroy loo_Sb
    return
end if

// Convert the contents of sb to the ITIDA canonical form.
// Always pass utf-8 for the 2nd arg.
loo_Sb.Encode("itida","utf-8")

ls_Canonical = loo_Sb.GetAsString()

Write-Debug ls_Canonical

// 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.
loo_SbExpected = create oleobject
li_rc = loo_SbExpected.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_SbExpected.LoadFile("qa_data/itida/sdk.invoicing.eta.gov.eg/files/one-doc-serialized.json.txt","utf-8")
if li_Success = 0 then
    Write-Debug "Failed to expected output file."
    destroy loo_Sb
    destroy loo_SbExpected
    return
end if

// Compare our computed canonical string with the expected result.
if loo_Sb.ContentsEqualSb(loo_SbExpected,1) = 1 then
    Write-Debug "The computed canonical result is correct."
else
    Write-Debug "The computed canonical result is NOT correct."
end if



destroy loo_Sb
destroy loo_SbExpected