JSON adds extra contents to a single file

Viewed 48

I have code that works something like this

import pandas as pd 
data = {
  "calories": [420, 380, 390],
  "duration": [50, 40, 45]
}

df = pd.DataFrame(data)

df.to_json("filename.json", orient = 'split')

In my actual code, the files are typically a few thousands rows long and they have string, date and numeric columns.

This code works fine about 95% of the time, but sometimes it writes extra contents to the file.

Instead of looking like this-

{"columns":["calories","duration"],"index":[0,1,2],"data":[[420,50],[380,40],[390,45]]}

It will look like this -

{"columns":["calories","duration"],"index":[0,1,2],"data":[[420,50],[380,40],[390,45]]}, [380, 40], [390, 45]]}

One easy way for me to spot when it happens is that there is always two } symbols.

Is this a known issue and, if so, what can I do to fix it?

0 Answers
Related