Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new feature/enhancement request: new JSON string option for pandas.DataFrame.to_json() #10244

Closed
gregrahn opened this issue Jun 1, 2015 · 4 comments
Labels
IO JSON read_json, to_json, json_normalize

Comments

@gregrahn
Copy link

gregrahn commented Jun 1, 2015

Currently pandas.DataFrame.to_json supports orient=records which yields a file of [{column -> value}, ... , {column -> value}] (as a single line). I'd like to request a slight variation of this format which is a single {column -> value} per line. This yields a similar format as PostgreSQL's row_to_json() function.

Example of the TPC-H region table using orient=records

[{"r_regionkey":0,"r_name":"AFRICA","r_comment":"lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to "},{"r_regionkey":1,"r_name":"AMERICA","r_comment":"hs use ironic, even requests. s"},{"r_regionkey":2,"r_name":"ASIA","r_comment":"ges. thinly even pinto beans ca"},{"r_regionkey":3,"r_name":"EUROPE","r_comment":"ly final courts cajole furiously final excuse"},{"r_regionkey":4,"r_name":"MIDDLE EAST","r_comment":"uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl"}]

desired new format:

{"r_regionkey":0,"r_name":"AFRICA","r_comment":"lar deposits. blithely final packages cajole. regular waters are final requests. regular accounts are according to "}
{"r_regionkey":1,"r_name":"AMERICA","r_comment":"hs use ironic, even requests. s"}
{"r_regionkey":2,"r_name":"ASIA","r_comment":"ges. thinly even pinto beans ca"}
{"r_regionkey":3,"r_name":"EUROPE","r_comment":"ly final courts cajole furiously final excuse"}
{"r_regionkey":4,"r_name":"MIDDLE EAST","r_comment":"uickly special accounts cajole carefully blithely close requests. carefully final asymptotes haggle furiousl"}
@jreback
Copy link
Contributor

jreback commented Jun 1, 2015

dupe of #9180, though I like your example data.

This would be a straightforward change in to_json, just pass another orient I think and implement in c.

pull-requests are welcome.

@jreback jreback added the IO JSON read_json, to_json, json_normalize label Jun 1, 2015
@jreback jreback added this to the Next Major Release milestone Jun 1, 2015
@bashtage
Copy link
Contributor

bashtage commented Jun 2, 2015

Isn't one just a regex replace away from the other?

@jorisvandenbossche
Copy link
Member

Unifiying the to_dict and to_json orients a bit would also be nice.

@WillAyd
Copy link
Member

WillAyd commented Aug 27, 2019

This is possible via df.to_json(orient="records", lines=True)

@WillAyd WillAyd closed this as completed Aug 27, 2019
@jorisvandenbossche jorisvandenbossche modified the milestones: Contributions Welcome, No action Aug 27, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

No branches or pull requests

5 participants