0

I have a data frame I'm attempting to export to a json file. Currently my fame looks something like this

PRICE    FRUIT    COLOR
1        Apple    Red
2        Orange   Orange

When I use the following JSON call:

df.to_json(orient='records',lines=True)

I return

{'Price':1,'Fruit':Apple,'Color':Red}
{'Price':2,'Fruit':Orange,'Color':Orange}

when I want

[{'Price':1,'Fruit':Apple,'Color':Red}
{'Price':2,'Fruit':Orange,'Color':Orange}]

So that the JSON file doesn't read each item as the end of file.

0

1 Answer 1

2

Just try

df.to_json(orient='records')

According to docs, if lines=True, pandas writes out line-delimited json format.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.