0

I want to change this dict:

{"entityMap": {}, "blocks": [{"key": "", "text": "Testing", "type": "unstyled", "depth": 0, "inlineStyleRanges": [], "entityRanges": [], "data": {}}]}

into this :

{\"entityMap\": {}, \"blocks\": [{\"key\": \"\", \"text\": \"Testing\", \"type\": \"unstyled\", \"depth\": 0, \"inlineStyleRanges\": [], \"entityRanges\": [], \"data\": {}}]}

I've tried this method:

json.dumps()

but the result is a double backslash

{\\"entityMap\\": {}, \\"blocks\\": [{\\"key\\": \\"\\", \\"text\\": \\"Testing\\", \\"type\\": \\"unstyled\\", \\"depth\\": 0, \\"inlineStyleRanges\\": [], \\"entityRanges\\": [], \\"data\\": {}}]}

How to achieve this in python?

takeiteasy
  • 61
  • 7
  • Could you give us [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)? – loloToster May 05 '21 at 18:18
  • it is working. - That is th expectd output - Python represents "\" in strings with a double \\ to mean an actual \ character, and not that it is escaping something els. Just see use `print(json.dumps(...))` to see what you actually got. – jsbueno May 05 '21 at 18:19
  • I need the exact value as in the "print" value, I can do this in this converter https://codebeautify.org/json-escape-unescape, but I don't know how to make it happen in python – takeiteasy May 05 '21 at 18:43

0 Answers0