Reputation: 21
everybody. I'm having problems working with json files. I have such a list of Json data , how can I insert this data to a table? Python code:
with open('object.json') as f:
json_obj = json.load(f)
print(json_obj)
for i in enumerate(json_obj):
id = validate_string(item.get("id", None))
LAST_NAME = validate_string(item.get("LAST_NAME", None))
FIRST_NAME = validate_string(item.get("FIRST_NAME", None))
cursor.execute("insert into EMPLOYEES (id,LAST_NAME,FIRST_NAME) VALUES (:1,:2,:3)", (id,LAST_NAME,FIRST_NAME))
conn.close
JSON some dates in the (object.json) file:
[{"ID": 1, "LAST_NAME": "Alex", "FIRST_NAME": "Pip"},
{"ID": 2, "LAST_NAME": "John", "FIRST_NAME": "Alan"},
{"ID": 3, "LAST_NAME": "Dehan", "FIRST_NAME": "Luck"},
{"ID": 4, "LAST_NAME": "Nick", "FIRST_NAME": "Adem"},
{"ID": 5, "LAST_NAME": "Aspen", "FIRST_NAME": "Turit"}]
DatabaseError: ORA-00904: "ID": invalid identifier
Upvotes: 0
Views: 2214
Reputation: 18780
ORA-904 is "invalid identifier".
create table test ("id" NUMBER, "Name" VARCHAR2(100));
INSERT INTO test (id, name) VALUES (1,'KOEN');
> gives ORA-00904: "NAME": invalid identifier
INSERT INTO test ("id", "Name") VALUES (1,'KOEN');
1 row(s) inserted.
More details here
Upvotes: 2