how to convert json to csv with python?
Peter Otten
__peter__ at web.de
Sat Jun 3 07:52:59 EDT 2017
Ho Yeung Lee wrote:
> after edit the file,
>
> Traceback (most recent call last):
> File "json2csv.py", line 148, in <module>
> loader.load(args.json_file)
> File "json2csv.py", line 53, in load
> self.process_each(json.load(json_file))
> File "C:\Python27\lib\json\__init__.py", line 291, in load
> **kw)
> File "C:\Python27\lib\json\__init__.py", line 339, in loads
> return _default_decoder.decode(s)
> File "C:\Python27\lib\json\decoder.py", line 364, in decode
> obj, end = self.raw_decode(s, idx=_w(s, 0).end())
> File "C:\Python27\lib\json\decoder.py", line 380, in raw_decode
> obj, end = self.scan_once(s, idx)
> ValueError: Expecting property name: line 38 column 1 (char 871)
>
> got another error
So have a look at line 38 and see if you find something suspicious.
{
...
"org": "AS9269 HKBN AS10103",
}
Unlike Python dict literals json does not allow the trailing comma a the end
of an {...} object. Compare:
>>> json.loads('{"a": 1}')
{'a': 1}
>>> json.loads('{"a": 1,}')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 359, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name enclosed in double quotes: line 1 column
9 (char 8)
More information about the Python-list
mailing list