FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour read json
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
read json
Posted: Sat Mar 14, 2026 06:12 AM

can someone help me read value seler: name: from this json

{
"invoices": [
{
"issueDate": "2026-02-28",
"permanentStorageDate": "2026-02-28T07:14:44.775212+00:00",
"invoicingDate": "2026-02-28T07:14:42.857831+00:00",
"acquisitionDate": "2026-02-28T07:14:42.960932+00:00",
"ksefNumber": "9662087281-20260228-39F91C400000-2C",
"invoiceNumber": "FU/61/02/2026",
"seller": {
"nip": "9662087281",
"name": "IDD Solutions Rusiłowicz spółka jawna"
},
"buyer": {
"identifier": {
"type": "Nip",
"value": "5423066262"
},
"name": "Apteka dr n. farm. Ewa Oksztulska-Kolanek"
},
"netAmount": 1262.1,
"grossAmount": 1552.38,
"vatAmount": 290.28,
"currency": "PLN",
"invoicingMode": "Online",
"invoiceType": "Vat",
"formCode": {
"systemCode": "FA (3)",
"schemaVersion": "1-0E",
"value": "FA"
},
"isSelfInvoicing": false,
"hasAttachment": false,
"invoiceHash": "BbkkqIaS9K9JdV5vaO8/TFsxBX+4b8mMEvEaDLPy3e0=",
"thirdSubjects": []
},
{
"issueDate": "2026-02-28",
"permanentStorageDate": "2026-02-28T02:40:28.912248+00:00",
"invoicingDate": "2026-02-28T02:40:21.176322+00:00",
"acquisitionDate": "2026-02-28T02:40:26.718344+00:00",
"ksefNumber": "5272643921-20260228-19D5060000EA-8F",
"invoiceNumber": "FV/23230/26/LM",
"seller": {
"nip": "5272643921",
"name": "POLSKA GRUPA FARMACEUTYCZNA S.A."
},
"buyer": {
"identifier": {
"type": "Nip",
"value": "5423066262"
},
"name": "APTEKA DR. N.FARM EWA OKSZTULSKA-KOLANEK"
},
"netAmount": 68.82,
"grossAmount": 74.33,
"vatAmount": 5.51,
"currency": "PLN",
"invoicingMode": "Online",
"invoiceType": "Vat",
"formCode": {
"systemCode": "FA (3)",
"schemaVersion": "1-0E",
"value": "FA"
},
"isSelfInvoicing": false,
"hasAttachment": false,
"invoiceHash": "4OByTzOInjChwJ15yqAItGQqvsM66HoHDm++lZOi7zs=",
"thirdSubjects": [
{
"identifier": {
"type": "Nip",
"value": "5423066262"
},
"name": "APTEKA OD SERCA DR.N.FARM EWA OKSZTULSKA-KOLANEK",
"role": 2
},
{
"identifier": {
"type": "Nip",
"value": "5272643921"
},
"name": "POLSKA GRUPA FARMACEUTYCZNA S.A.",
"role": 0
}
]
}
]
}


--------------------------------------------------

thanks at all
kajot

best regards

kajot
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: read json
Posted: Sat Mar 14, 2026 08:14 AM

Dear Kajot,

LOCAL hData  
  

IF hb_jsonDecode(cJson, @hData) == 0  

    ? "Error al decodificar el JSON"  

    RETURN  

ENDIF  
  

// Acceder al array de facturas  

FOR EACH oInvoice IN hData["invoices"]  

    ? "Seller Name:", oInvoice["seller"]["name"]  

NEXT
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: read json
Posted: Sat Mar 14, 2026 08:23 AM
LOCAL cJson := MemoRead("data.json")
LOCAL hData
LOCAL aInvoices
LOCAL i, cSellerName

// Decode JSON
hb_jsonDecode( cJson, @hData )

// Get invoices array
aInvoices := hData["invoices"]

FOR i := 1 TO Len( aInvoices )
   cSellerName := aInvoices[i]["seller"]["name"]
   ? "Seller name:", cSellerName
NEXT
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: read json
Posted: Sat Mar 14, 2026 08:45 AM

thanks

best regards

kajot
Posts: 199
Joined: Fri Apr 18, 2008 04:21 PM
Re: read json
Posted: Sat Mar 21, 2026 05:30 AM

Puedes descargar esta clase tJson puede ser otra opcion

https://cgtecsa.com/Proyectos/tJson.zip

y te dejo el ejemplo de como poder usarla

local oJSON, oInvoices, oInv, oSeller, oBuyer, oFormCode, oThird
local i, j, nCount

// Parsear el JSON (desde string o archivo)
oJSON := TJSON():New()
oJSON:Parse( cMiJSON ) // o bien: oJSON:LoadFromFile( "archivo.json" )

// Acceder al array de invoices
oInvoices := oJSON:Get("invoices") // Retorna un TJSON con lIsArray = .T.

// Recorrer cada factura
nCount := oInvoices:ArrayLen()
For i := 1 to nCount

oInv := oInvoices:GetItem( i ) // Cada item es un TJSON (objeto)

// Campos simples
? "Fecha:", oInv:Get("issueDate")
? "KSeF #:", oInv:Get("ksefNumber")
? "Factura #:", oInv:Get("invoiceNumber")
? "Neto:", oInv:Get("netAmount") // 1262.1 (numerico)
? "Bruto:", oInv:Get("grossAmount")
? "IVA:", oInv:Get("vatAmount")
? "Moneda:", oInv:Get("currency")
? "Self-invoicing:", oInv:Get("isSelfInvoicing") // .F. (logico)

// Sub-objeto seller (acceso directo)
oSeller := oInv:Get("seller")
? "Vendedor NIP:", oSeller:Get("nip")
? "Vendedor:", oSeller:Get("name")

// Sub-objeto seller (acceso con ruta de puntos - alternativa)
? "Vendedor NIP:", oInv:Get("seller.nip")
? "Vendedor:", oInv:Get("seller.name")

// Sub-objeto buyer
? "Comprador:", oInv:Get("buyer.name")
? "Comprador NIP:", oInv:Get("buyer.identifier.value")
? "Tipo ID:", oInv:Get("buyer.identifier.type")

// Sub-objeto formCode
? "System code:", oInv:Get("formCode.systemCode")
? "Schema ver:", oInv:Get("formCode.schemaVersion")

// Array thirdSubjects
oThird := oInv:Get("thirdSubjects") // TJSON array
if oThird != nil .and. oThird:ArrayLen() > 0
? "--- Third subjects ---"
For j := 1 to oThird:ArrayLen()
? " Nombre:", oThird:GetItem(j):Get("name")
? " NIP:", oThird:GetItem(j):Get("identifier.value")
? " Role:", oThird:GetItem(j):Get("role")
Next
endif

? Replicate("-", 60)
Next

Atentamente
Julio Ponce

Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: read json
Posted: Sat Mar 21, 2026 02:35 PM

thank You

best regards

kajot

Continue the discussion