#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json, os
from os.path import isfile, join
path_arr = ["['data']['variables']['startupProcessInfo']['iin']",
"['data']['piid']",
"['data']['executionState']",
"['data']['creationTime']"]
onlyfiles = [f for f in os.listdir('in') if isfile(join('in', f))]
print(onlyfiles)
for fles in onlyfiles:
i = 0
infile = open(os.path.join('in', fles), 'r')
data_item = json.load(infile)
while i < len(path_arr):
print(data_item(path_arr[i]))
i += 1
Traceback (most recent call last):
File "path_arr.py", line 19, in <module>
print(data_item(path_arr[i]))
TypeError: 'dict' object is not callable
for fles in onlyfiles:
data_item = json.load(fles)
inn_v = (data_item['data']['variables']['startupProcessInfo']['iin'])
inn2_v = (data_item['data']['variables']['startupProcessInfo']['iin2'])
inn3_v = (data_item['data']['variables']['startupProcessInfo']['iin3'])
...
inn130_v = (data_item['data']['variables']['startupProcessInfo']['iin130'])
statement = 'insert into ....'
json_curr.execute(statement, row)
"['data']['variables']['startupProcessInfo']['iin']"
"['data']['variables']['startupProcessInfo']['iin2']"
"['data']['variables']['startupProcessInfo']['iin3']"
...
"['data']['variables']['startupProcessInfo']['iin130']"
for fles in onlyfiles:
data_item = json.load(fles)
inn_arr = []
for path_str in 'json_def':
try:
tmp_str = data_item(path_str )
inn_arr.append(data_item(path_str))
except:
print("error")
statement = 'insert into json_tbl () value (inn_arr)'
json_curr.execute(statement)