I have a json file which i recieved from source in below format. { "api_version": "1.3", "response_code": "200", "id": "3237490513229753", "lon": "38.969916127827", "lat": "45.069889625267", "page_url": null, "name": "ATB", "firm_group": { "id": "3237499103085728", "count": "1" }, "city_name": "Krasnodar", "city_id": "3237585002430511", "address": "Turgeneva, 172/1", "create_time": "2008-07-22 10:02:04 07", "modification_time": "2013-08-09 20:04:36 07", "see_also": [ { "id": "3237491513434577", "lon": 38.973110606808, "lat": 45.029031222211, "name": "Advance", "hash": "5698hn745A8IJ1H86177uvgn94521J3464he26763737242Cf6e654G62J0I7878e", "ads": { "sponsored_article": { "title:"aman", "text": "Business.English." }, "warning": null } } ] } I know there is syntax issue in title key not enclosed in double quotes.How can I fix this basic syntax issues of json file automatically? Any help will be much apprecited.
Asked
Active
Viewed 45 times
0
-
Does this answer your question? [Python - Invalid JSON format - how to parse](https://stackoverflow.com/questions/51355495/python-invalid-json-format-how-to-parse) – Joe Oct 25 '20 at 07:46
-
@Joe I am getting below error. – KHYATI AMAN Oct 25 '20 at 08:06
-
Traceback (most recent call last): File "json_parser.py", line 5, in
data = json.loads(re.sub(r"(\w+):", r'"\1":', jstring)) File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads return _default_decoder.decode(s) File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting ',' delimiter: line 16 column 33 (char 403) – KHYATI AMAN Oct 25 '20 at 08:07 -
Below is the code. – KHYATI AMAN Oct 25 '20 at 08:07
-
import re import json with open("/home/ec2-user/environment/test2.json") as infile: jstring = infile.read() data = json.loads(re.sub(r"(\w+):", r'"\1":', jstring)) print(data) – KHYATI AMAN Oct 25 '20 at 08:07