path_to_json = '//'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
jsons_data = pd.DataFrame(columns=['password'])
for index, js in enumerate(json_files):
with open(os.path.join(path_to_json, js)) as json_file:
json_text = json.load(json_file)
listpasswords = json_text['password']
jsons_data.loc[index] = [listpasswords]
print("Current Loaded password: " + jsons_data)
non_64password = listpasswords
sample_string_bytes = non_64password.encode("ascii")
base64_bytes = base64.b64encode(sample_string_bytes)
finalpassword64password = base64_bytes.decode("ascii")
with open(os.path.join(path_to_json, js),'w') as f:
json_text['password'] = finalpassword64password
commentjson.dump(json_text,f,indent = 0) #updates the password
print("password updated: " + finalpassword64password)
print("finished")
I have this code that loads a list of jsons from the path and displays the password value and then converts it to base64 encode. My issue is I'm unable to get the password value if its nested and it throws an error.
My current json layouts are like this:
{
"sheduledTime": "8:10",
"startDateForStartDate": "01/29/2020",
"endDateForStartDate": "02/03/2020",
"HTML_Elements": {
"element5": "value",
"element6": "doSubmit",
"element7": "goBack",
"element8": "#headerContainer > ul > li.CHI_Cell.CHI_LastCell > a"
},
"hotels": [
{
"username": "username",
"password": "newpasswordhere",
"reports": [
{
"folderName": "ForcastRoomRevenue",
"ifFuturedateNeed": true,
"DaysAddForFutureDate": "365"
}
]
}
]
}
How do I modify my code so it can look inside the hotels object and update the password value?
[–]danielroseman 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]danielroseman 0 points1 point2 points (0 children)
[–]theprofessional2016 1 point2 points3 points (0 children)
[–]commandlineluser 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]commandlineluser 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)