0

When I want to save my JSON it adds backslashes and double quotes to it. So the single quote around is getting replaced with double quotes and it adds the slashes

'{"created_at":"foo","created_by":"foo"}'

So when I open the saved file it looks like this

"{\"created_at\":\"foo\",\"created_by\":\"foo\"}"

and i need to have it like this

{"created_at":"foo","created_by":"foo"}

My code looks like this: For saving

with open('data3.json', 'w', encoding='utf-8') as f:
    json.dump(data3, f, ensure_ascii=False)
2

1 Answer 1

1

Saving with the following code:

import json 
test = {"created_at":"foo","created_by":"foo"}
with open('data3.json', 'w', encoding='utf-8') as f:
json.dump(test, f, ensure_ascii=False)

I get the following: {"created_at": "foo", "created_by": "foo"}

try editing your notepad++ setting maybe something about their display.

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

2 Comments

maybe it's important to mention that the json looks like this befor saving it '{"created_at":"foo","created_by":"foo"}', so there is this single quote around it
you should maybe convert it to dict type or use json loads before writing to file.

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.