> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Convert DataFrame to JSON without Backslash in Pandas
- URL: https://datascientyst.com/convert-dataframe-to-json-without-backslash-in-pandas/
- Published: 2023-03-17T21:56:19.000Z
- Updated: 2024-04-09T10:02:28.000Z
- Author: John D K
- Tags: to_json()

In this short tutorial, you'll see the steps to convert DataFrame to JSON without backslash escape in Pandas and Python.

**Note:** Read also: [How to Export DataFrame to JSON with Pandas ](https://datascientyst.com/export-dataframe-to-json-pandas/)

![](https://datascientyst.com/content/images/2023/03/convert-dataframe-to-json-without-backslash-in-pandas.webp)

Suppose we have the following DataFrame:

|   | Name    | Age | site                |
| - | ------- | --- | ------------------- |
| 0 | Alice   | 25  | http://example.com/ |
| 1 | Bob     | 30  | http://example.com/ |
| 2 | Charlie | 35  | http://example.com/ |

Here is the result of the conversion with `to_json()` with option `orient='records'`:

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

```

We get a valid JSON file but with extract backslashes:

```
{"Name":"Alice","Age":25,"site":"http:\/\/example.com\/"}
{"Name":"Bob","Age":30,"site":"http:\/\/example.com\/"}
{"Name":"Charlie","Age":35,"site":"http:\/\/example.com\/"}

```

To convert Pandas DataFrame to JSON file without backslash escapes:

```python
formatted_json = df.to_json(orient='records',lines=True).replace('\\/', '/')
print(formatted_json)

```

This will replace all additional backslash escapes with:

```
{"Name":"Alice","Age":25,"site":"http://example.com/"}
{"Name":"Bob","Age":30,"site":"http://example.com/"}
{"Name":"Charlie","Age":35,"site":"http://example.com/"}

```

To store the JSON data as a file without backslash we can do:

```python
print(formatted_json, file=open('data.json', 'w'))

```

We can get this result without `lines=True`:

```
[
{
"Name": "Alice",
"Age": 25,
"site": "http://example.com/"
},
{
"Name": "Bob",
"Age": 30,
"site": "http://example.com/"
},
{
"Name": "Charlie",
"Age": 35,
"site": "http://example.com/"
}
]

```