Need to import Json To Dbf

276 views
Skip to first unread message

Vikram Chhajer

unread,
Jan 27, 2023, 8:03:10 AM1/27/23
to Harbour Users
Hello Experts 
Need to write a programme to import This json to Dbf  , but how to do ? please Help me to resolve this issue 

 {"ok":true,"result":[{"update_id":705970127, "message":{"message_id":540,"from":{"id":332303624,"is_bot":false,"first_name":"Nagesh","last_name":"Pawar","username":"Nahesh_pawar","language_code":"en"},"chat":{"id":332303624,"first_name":"Nagesh","last_name":"Pawar","username":"Nahesh_pawar","type":"private"},"date":1674807048,"text":"hello"}},{"update_id":705970128, "message":{"message_id":541,"from":{"id":5324591,"is_bot":false,"first_name":"V","last_name":"Never Stop Learning","username":"vikramchhajer","language_code":"en"},"chat":{"id":5324591,"first_name":"V","last_name":"Never Stop Learning","username":"vikramchhajer","type":"private"},"date":1674807096,"text":"Hello"}},{"update_id":705970129, "message":{"message_id":542,"from":{"id":42817288,"is_bot":false,"first_name":"V","username":"Chhajervikram","language_code":"en"},"chat":{"id":42817288,"first_name":"V","username":"Chhajervikram","type":"private"},"date":1674807118,"text":"Hello"}},{"update_id":705970130, "message":{"message_id":543,"from":{"id":5935597341,"is_bot":false,"first_name":"FrontRange","language_code":"en"},"chat":{"id":5935597341,"first_name":"FrontRange","type":"private"},"date":1674807132,"text":"Hello"}}]}


Thanks In Advacne .

Vikram


Gerald Drouillard

unread,
Jan 27, 2023, 12:12:42 PM1/27/23
to harbou...@googlegroups.com
hb_jsonDecode()

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/14634d1b-31b2-4dd0-bce3-73346183e738n%40googlegroups.com.

HBQuerier

unread,
Jan 29, 2023, 6:27:41 PM1/29/23
to Harbour Users

Yakano

unread,
Jan 31, 2023, 2:41:29 AM1/31/23
to Harbour Users
Hi Vikram

This is NOT my answer, it's just ChatGPT, from openai (https://chat.openai.com/chat) ...

#include "hbjson.ch"

Function Main()

   Local cFileJSON := "datos.json"
   Local cFileDBF := "datos.dbf"
   Local oJSON := JsonToArray( HB_JsonParseFile( cFileJSON ) )
   Local aFields := Array( { "CAMPO1", "C", 20 }, { "CAMPO2", "N", 10, 0 }, { "CAMPO3", "D" } )
   
   // Crear el archivo dbf
   If ! File( cFileDBF )
      DBCreate( cFileDBF, aFields )
   EndIf
   
   // Abrir el archivo dbf
   Use ( cFileDBF )
   
   // Insertar los datos desde el archivo json
   For Each oReg In oJSON
      Append Blank
      Replace CAMPO1 With oReg.CAMPO1
      Replace CAMPO2 With oReg.CAMPO2
      Replace CAMPO3 With oReg.CAMPO3
   Next
   
   // Cerrar el archivo dbf
   Use

Return

Best regards

Jayadev U

unread,
Feb 1, 2023, 8:54:10 AM2/1/23
to harbou...@googlegroups.com

Hi Yakano,

 

Are these functions available in Harbour:

 

1.       JsonToArray()

2.       HB_JsonParseFile()

 

Also, where is the file hbjson.ch located.

 

If you have created UDFs, could you please share.

 

Warm regards,

 

Jayadev’

--

You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.

HBQuerier

unread,
Feb 1, 2023, 1:30:52 PM2/1/23
to Harbour Users
Is there a .ch?  There's a C header file at c:\<HBFOLDER>\include\hbjson.h

Yakano

unread,
Feb 3, 2023, 4:53:00 AM2/3/23
to Harbour Users
Hi Yayadev, HBQuerier

Harbour "Hash" is so simililar to "Json" ...

// Coding Hash=>Json
hHash := {=>}
hHash := hb_HSet(hHash, 'VAR1', cVar1)
hHash := hb_HSet(hHash, 'VAR2',vVar2))
hHash := hb_HSet(hHash, 'VAR3', hb_Translate(cVar3 "ES437","UTF8")) 
cPost := hb_jsonEncode(hHash, .f.)

// Decoding Json=>Hash
hb_jsonDecode(cStrFile, @hHash)
if !Empty(hHash) .and. hb_HHasKey(hHash["answer"], 'OK')
   cVar1 := hb_HGetDef(hHash[" answer  "][" OK  "], 'Data1', '')
   cVar2 := hb_HGetDef(hHash[" answer  "][" OK  "], 'Data2', '')
   cVar3 := hb_HGetDef(hHash[" answer  "][" OK  "], 'Data3', '')
endif

// Including 
#include "hbjson.ch"
Is ChatGPT answer, I Don't use this, the hb_[functions] works forme...

Best regards

Auge & Ohr

unread,
Feb 3, 2023, 7:54:13 PM2/3/23
to Harbour Users
hi,

when use ChatGPT please also post your Question so we can "verify" if ChatGPT will produce similar Answer
Reply all
Reply to author
Forward
0 new messages