-1
Next, I’m developing a Python program that collects data from a JSON and transfers it to a CSV file.
However, the server routine brings me a JSON with the wrong structure at some points of it, as in this case:
...
"Campo": valor,
"Campo": "valor"
},
[
{}
][
{
"Campo": valor,
"Campo": {},
...
When I run the program (which works perfectly with JSON files formatted correctly) with this JSON, it returns me the error:
File "C:\Users\mpolillo\Documents\json-extraction\script\fix_json.py", line 17, in fix_test
content = json.loads(content)
File "C:\Users\mpolillo\AppData\Local\Continuum\anaconda3\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\mpolillo\AppData\Local\Continuum\anaconda3\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\mpolillo\AppData\Local\Continuum\anaconda3\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 123944 column 2 (char 3653439)
I mean, you’re warning me on the line where this mistake is. I wanted to know if there is any way to rewrite this JSON without having to do it manually or without having Python rewrite everything in hand and then write it in a new file or on top of it.
Who generates these JSON? What would be
valor
of the second line of the JSON that posted in the question?– Woss
It is a routine written in Typescript. The
valor
andcampo
are just illustrative names, because you have bank information that I can’t put in. The point is, I can’t make changes to the routine, I have to find a way to fix this JSON in the program itself.– Matheus Marques Polillo