0

I have a bunch of json escaped strings, for example

str = "what a war\/what a peace"

(the escape doesn't limit to slash "/")

I want to parse it to

"what a war/what a peace"

How can I do it with python 3.0 ?

Hello lad
  • 17,344
  • 46
  • 127
  • 200

1 Answers1

0

Is there anything stopping your from using the built-in replace on string instances?

s = "what a war\/what a peace"
r = s.replace('\\', '')
print(r)
'what a war/what a peace'

As an addendum, I know this in an example of what you want to do but, refrain from using names like str, list et-cetera. You'll regret it later.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
  • thanks for the suggestion. I fear there is other escape which is not covered by this replacement. is there? – Hello lad Sep 21 '16 at 17:14
  • According to [this q&a](http://stackoverflow.com/questions/19176024/how-to-escape-special-characters-in-building-a-json-string) `json` too uses `\` to escape things so I'm guessing you would be ok. – Dimitris Fasarakis Hilliard Sep 21 '16 at 17:27