Working on a JSON Project
Moderator: Rathinagiri
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Working on a JSON Project
Friends,
I am working on a JSON navigator/browser/viewer Project.
Even though initially I have tried and struggled to use HB_Hash functions, it became now easy for me to start the project with SQLite JSON1 Extension and hmgsqlite bridge.
I have completed the basic functionality of navigating through a JSON file/Text.
I am working on exporting the tables to Excel. Please suggest other features also if you want.
The whole project is uploaded along with the Exe file here.
viewtopic.php?p=55926#p55926
I am working on a JSON navigator/browser/viewer Project.
Even though initially I have tried and struggled to use HB_Hash functions, it became now easy for me to start the project with SQLite JSON1 Extension and hmgsqlite bridge.
I have completed the basic functionality of navigating through a JSON file/Text.
I am working on exporting the tables to Excel. Please suggest other features also if you want.
The whole project is uploaded along with the Exe file here.
viewtopic.php?p=55926#p55926
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3167
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Working on a JSON Project
Thanks Rathi,
At the moment I can't think of any extra functionality. I will let you know!
Serge
At the moment I can't think of any extra functionality. I will let you know!
Serge
There's nothing you can do that can't be done...
- serge_girard
- Posts: 3167
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Working on a JSON Project
Rathi, some functions are missing ? : connect2db, miscsql, ...
Serge
Serge
There's nothing you can do that can't be done...
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Working on a JSON Project
It is HMG Connectivity HMGSQLite bridge. Otherwise, you can also use this code.
Code: Select all
#include <hmg.ch>
FUNCTION connect2db(dbname,lCreate)
local dbo1 := sqlite3_open(dbname,lCreate)
IF Empty( dbo1 )
msginfo("Database could not be connected!")
RETURN nil
ENDIF
RETURN dbo1
function sql( dbo1, qstr )
local table := {}
local currow := nil
local tablearr := {}
local rowarr := {}
local typesarr := {}
local current := ""
local i := 0
local j := 0
local type1 := ""
local stmt := nil
local cDate
if empty(dbo1)
msgstop("Database Connection Error!")
return tablearr
endif
table := sqlite3_get_table(dbo1,qstr)
if sqlite3_errcode(dbo1) > 0 // error
msgstop(sqlite3_errmsg(dbo1)+" Query is : "+qstr)
return nil
endif
stmt := sqlite3_prepare(dbo1,qstr)
IF ! Empty( stmt )
for i := 1 to sqlite3_column_count( stmt )
type1 := HMG_UPPER(alltrim(sqlite3_column_decltype( stmt,i)))
do case
case type1 == "INTEGER" .or. type1 == "REAL" .or. type1 == "FLOAT" .or. type1 == "DOUBLE"
aadd(typesarr,"N")
case type1 == "DATE" .or. type1 == "DATETIME"
aadd(typesarr,"D")
case type1 == "BOOL"
aadd(typesarr,"L")
otherwise
aadd(typesarr,"C")
endcase
next i
endif
SQLITE3_FINALIZE( stmt )
stmt := nil
if HMG_LEN(table) > 1
asize(tablearr,0)
for i := 2 to HMG_LEN(table)
rowarr := table[i]
for j := 1 to HMG_LEN(rowarr)
do case
case typesarr[j] == "D"
cDate := HB_USUBSTR(rowarr[j],1,4)+HB_USUBSTR(rowarr[j],6,2)+HB_USUBSTR(rowarr[j],9,2)
rowarr[j] := stod(cDate)
case typesarr[j] == "N"
rowarr[j] := val(rowarr[j])
case typesarr[j] == "L"
if val(rowarr[j]) == 1
rowarr[j] := .t.
else
rowarr[j] := .f.
endif
endcase
next j
aadd(tablearr,aclone(rowarr))
next i
endif
return tablearr
function miscsql(dbo1,qstr)
if empty(dbo1)
msgstop("Database Connection Error!")
return .f.
endif
sqlite3_exec(dbo1,qstr)
if sqlite3_errcode(dbo1) > 0 // error
msgstop(sqlite3_errmsg(dbo1)+" Query is : "+qstr)
return .f.
endif
return .t.
function C2SQL(Value)
local cValue := ""
local cdate := ""
if ( valtype(value) == "C" .or. valtype( value ) == "M" ) .and. HMG_LEN(alltrim(value)) > 0
value := HB_UTF8STRTRAN(value, "'", "''" )
endif
do case
case Valtype(Value) == "N"
cValue := AllTrim(Str(Value))
case Valtype(Value) == "D"
if !Empty(Value)
cdate := dtos(value)
cValue := "'"+HB_USUBSTR(cDate,1,4)+"-"+HB_USUBSTR(cDate,5,2)+"-"+HB_USUBSTR(cDate,7,2)+"'"
else
cValue := "''"
endif
case Valtype(Value) $ "CM"
IF Empty( Value)
cValue="''"
ELSE
cValue := "'" + value + "'"
ENDIF
case Valtype(Value) == "L"
cValue := AllTrim(Str(iif(Value == .F., 0, 1)))
otherwise
cValue := "''" // NOTE: Here we lose values we cannot convert
endcase
return cValue
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: Working on a JSON Project
Thank you Rathi, It is very much required
Copy / Paste / Search / Replace and re-export json file
Also visit Freeware tools including json viwer
http://www.mitec.cz/jsonv.html
Copy / Paste / Search / Replace and re-export json file
Also visit Freeware tools including json viwer
http://www.mitec.cz/jsonv.html
BPD
Convert Dream into Reality through HMG
Convert Dream into Reality through HMG
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Working on a JSON Project
Thank you for the link. It is so cool!
However, these free viewers are just creating a big tree of all objects. What we require is to treat the Arrays and Objects in a different way.
Wow! The possibilities of HMG are unimaginable! Now I have improved a lot with some code changes to flatten all the tables in the JSON and show them in a single window with different tab pages.
Try to walk through the attached sample JSON file (a real Indian GST file) with my viewer. I think you will see the difference.
Now it is time to format and export.
Give your suggestions also.
However, these free viewers are just creating a big tree of all objects. What we require is to treat the Arrays and Objects in a different way.
Wow! The possibilities of HMG are unimaginable! Now I have improved a lot with some code changes to flatten all the tables in the JSON and show them in a single window with different tab pages.
Try to walk through the attached sample JSON file (a real Indian GST file) with my viewer. I think you will see the difference.
Now it is time to format and export.
Give your suggestions also.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3167
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Working on a JSON Project
Great tool Rathi!
Serge
Serge
There's nothing you can do that can't be done...
Re: Working on a JSON Project
Excellent Rathinagiri.
Warm regards,
Jayadev
Warm regards,
Jayadev
Re: Working on a JSON Project
Great sample code for json parsing Rathinagiri Sir. Thanks for it.
Regards,
Anand
Regards,
Anand
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Working on a JSON Project
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.