-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add indent support to to_json
method
#12004
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
Comments
Another workaround: |
Is it still on the list to be implemented? |
Still open. Feel free to work on it if you want, but the current json isn't the friendliest. |
@TomAugspurger Ok, got it! I'll try to figure out if there is a straightforward way to deal with it. |
It looks like the JSON writer uses Pandas' own JSON writer: Line 7 in 011b79f
It looks like eventually it calls pandas/pandas/_libs/src/ujson/python/objToJSON.c Lines 2317 to 2321 in 011b79f
So if I'm not mistaken, to add an |
Yep that sounds right. FYI, I think ripping out that JSON code and
replacing it with something more maintainable
(maybe based on Apache Arrow's JSON support) is on the medium to long-term
agenda.
…On Mon, Nov 12, 2018 at 9:28 AM Kyle Barron ***@***.***> wrote:
It looks like the JSON writer
<https://github.com/pandas-dev/pandas/blob/011b79fbf73b45313b47c08b4be1fc07dcb99365/pandas/io/json/json.py#L107-L117>
uses Pandas' own JSON writer:
https://github.com/pandas-dev/pandas/blob/011b79fbf73b45313b47c08b4be1fc07dcb99365/pandas/io/json/json.py#L7
It looks like eventually it calls objToJSON in C here:
https://github.com/pandas-dev/pandas/blob/011b79fbf73b45313b47c08b4be1fc07dcb99365/pandas/_libs/src/ujson/python/objToJSON.c#L2317-L2321
So if I'm not mistaken, to add an indent option, you'd need to change the
C code?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12004 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIiHGfDOPOU98wggIOgkOVEaLVrPgks5uuZOKgaJpZM4HBmld>
.
|
Is the current JSON writer believed to be much faster than the Python standard library's JSON writer? |
Yep. It also handles types not supported by the stdlib's json writer
(notably numpy types).
…On Mon, Nov 12, 2018 at 9:55 AM Kyle Barron ***@***.***> wrote:
Is the current JSON writer believed to be much faster than the Python
standard library's JSON writer?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12004 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHIvmwtHI6ob3U9Tb4WZVI97EsrOd8ks5uuZn9gaJpZM4HBmld>
.
|
I agree on this, JSON is also meant to be human readable. Right now this is just annoying. |
Sometimes you just want to have a quick look at your data in IPython and having
to_json
to supportindent
(as bothjson.dumps
andsimplejson.dumps
do) would be very handy.A workaround, which however doesn't always work, is to do
json.dumps(series.to_dict())
, which unfortunately is annoying when you don't have a JSON-serializable type (e.g.,numpy.bool_
).I'm leaving this here as a food for discussion.
The text was updated successfully, but these errors were encountered: