Skip to content

Conversation

@u7955901
Copy link

Added code in the to_json() function in pandas/io/json/__json.py file.
Will replace escaped forward slashes with forward slashes if escape_forward_slashes parameter is set to False.
Particularly useful for file paths, so the path doesn't get changed.

@u7955901
Copy link
Author

pre-commit.ci autofix

@u7955901
Copy link
Author

Hi, the test for Pandas for Pyodide is failing, I'm not sure why because the parts of the repository it relates to I haven't changed. Is this an issue that requires changes in my code to fix?

assert result == expected


def test_to_json_escape_forward_slashes():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a test that also escapes forward slash?

) as handles:
handles.handle.write(s)
else:
if not escape_forward_slashes:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only apply if you are not writing to a file.

for letter in s:
if skip is False:
if letter + s[i] == pattern:
new_s = new_s + r"/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this shouldn't be done in python as a post-processing step. Ideally, you should change the behavior on the C implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: add option to save json without escaping forward slashes

3 participants