I use the below python code to manipulate a set of JSON files in a specified folder. I extract nt
from the data and I want to create new key value pair. If I were to print nt
on my screen I get values as shown below.
nt 223
nt 286
nt 315
These looks like integers to me. However If I use Kibana visualization tool to process it says this (i.e NXT
is an analysed string fields). I want these values to be recognized as integers? Does this have something to do with the way I am encoding my json file (ensure_ascii=True
) or is JSON value
always a string?
#Process 'new' events to extract more info from 'Messages'
rootDir = '/home/s_parts'
for dirName, subdirList, fileList in os.walk(rootDir):
for fname in fileList:
fname='s_parts/'+fname
with open(fname, 'r+') as f:
json_data = json.load(f)
m = json_data['Msg']
nt = int(re.findall(r"NXT:\s*([^,m)]*)",m)[0])
json_data["NXT"] = nt
f.seek(0)
json.dump(json_data,f,ensure_ascii=True)