I have a JSON file in the following format -
Note the characters after 1 and 2 (etc) represent strings written without double quotes
{
"Apparel": {
"XX": {
"1": YY,
"2": ZZ
},
"TT": {
"1":TTT,
"2":TTT,
"3": TTT,
"4": TTT
},
"XXX": {
"1":XXX,
"2":XXX
},
"RRR": {
"1":RRR,
"2":RRR
},
"AAA": {
"1":AAA,
"2":AAA,
"3":AAA
},
}
....
And so on.
Now I know that the file is not correctly formatted (the file is being kept this way because of design or something idk) and using it with the standard json module in Python3 will give a decode error but I've been told to use the file as it is. Which means any problems, I'll have to sort in my code. I need to pick the values after 1
from every heading, then values from 2
from every heading and so on.
Currently I'm using this code to read the file -
import json
with open("brand_config.json") as json_file:
json_data = json.load(json_file)
test = (json_data["apparel"]["biba"])
print (test)
This code gives this error -
Traceback (most recent call last):
File "reader.py", line 4, in <module>
json_data = json.load(json_file)
File "/usr/lib/python3.5/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 4 column 9 (char 36)
How do I read the required values without changing anything in the JSON file.