I have text files that include this data:
SSID: Wudi, quality: 86%
SSID: Vodafone_ADSL_2018, quality: 92%
SSID: Akram, quality: 43%
SSID: WE_BAE8DF, quality: 31%
SSID: BlzS-b21hcjE5MjE5OTg, quality: 31%
SSID: OPPO A53, quality: 31%
SSID: Vodafone_ADSL_2018, quality: 92%
SSID: WIFI 1, quality: 87%
SSID: , quality: 31%
SSID: pretty angel, quality: 31%
SSID: NETGEAR, quality: 84%
SSID: Akram, quality: 40%
SSID: memo, quality: 85%
SSID: Wudi, quality: 86%
SSID: AndroidAP63FC, quality: 38%
So I want to convert my text file to JSON. I have tried this code:
import json
filename = 'data_quality/quality-2021-11-21_12-10-21.908466.txt'
dict1 = {}
with open(filename) as fh:
for line in fh:
command, description = line.strip().split(None, 1)
dict1[command] = description.strip()
out_file = open("testooo.json", "w")
json.dump(dict1, out_file, indent=4, sort_keys = False)
out_file.close()
but it gives me the file in that format:
{
"SSID:": "AndroidAP63FC, quality: 38%"
}
but I need the file to be formatted like that: first, delete the "SSID" then it becomes
{
"AndroidAP63FC, quality": "38%",
"Wudi, quality": "86%",
"Vodafone_ADSL_2018, quality:" "92%",
and so on...
}
Note: I have more than 1000 files so I want to do it with code.