Mar-02-2024, 08:25 PM
Hi All,
I have written the following code to generate json file from oracle database, and the file doesn't have the Keys(Columns) only values printing in the file. Also no curly braces. Below is the output too. Please assit me on this.
Jay
I have written the following code to generate json file from oracle database, and the file doesn't have the Keys(Columns) only values printing in the file. Also no curly braces. Below is the output too. Please assit me on this.
import oracledb import datetime import json try: oracledb.init_oracle_client() con = oracledb.connect(connectioninfo) except oracledb.DatabaseError as er: print('There is an error in the Oracle database:', er) else: try: cur = con.cursor() # fetchall() is used to fetch all records from result set cur.execute('select emp_no,first_name,salary,dept_no from emp') rows = cur.fetchall() print(rows) save_file = open("emp.json", "w") json.dump(rows, save_file, indent = 6) save_file.close() with open("emp.json") as j_out: saved_data = json.load(j_out) print(saved_data) except oracledb.DatabaseError as er: print('There is an error in the Oracle database:', er) except Exception as er: print('Error:'+str(er)) finally: if cur: cur.close() finally: if con: con.close()
Output:Output:
[
[
1,
"Jay",
24000.0,
10
],
[
2,
"Rn",
34000.0,
10
]
}
Thanks Jay