Python Forum
Remove escape characters / Unicode characters from string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove escape characters / Unicode characters from string
I retrieve some JSON from a web page. It is real JSON, however due to all the backslash escape characters it doesn't want to format correct.
There's two fixes I've though of although I'm not sure how to do either.

Here's a snippet of the JSON:
\"text_with_blanks\":\"<b>Tagesmen\\u00fc im Restaurant<\\\/b><br\\\/>\\u00a0Samstag, 12. August<br\\\/>\\u00a0<b>Suppen<\\\/b><br\\\/>Tomatensuppe \\u00a0 \\u00a0 \\u00a0 \\u00a0 \\u00a0 \\u00a0 \\u00a0 \\u00a0
As you can see, not only is it full of "\" it's also full of unicode characters.

The first method was to remove backslashes. If I did that with .replace() it would get rid of every backslash of course, so I need a way to get rid of only one backslash everytime it encounters a backslash.

The other method is to firstly, convert the unicode characters to actual characters, and then replace all the backslashes but I'm not sure how I would go about coverting the characters. Sadly, decode("utf-8") doesn't work.

Whats the best way to do this?

Messages In This Thread
Remove escape characters / Unicode characters from string - by DreamingInsanity - May-14-2020, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read characters of line and return positions Gizzmo28 2 152 Nov-04-2020, 09:27 AM
Last Post: perfringo
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 210 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Print characters in a single line rather than one at a time hhydration 1 220 Oct-10-2020, 10:00 PM
Last Post: bowlofred
  get two characters, count and print from a .txt file Pleiades 9 415 Oct-05-2020, 09:22 AM
Last Post: perfringo
  How to remove char from string?? ridgerunnersjw 2 160 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  Pressing non-latin characters? Murlog 0 274 Jul-25-2020, 03:10 PM
Last Post: Murlog
  Introduction to escaping characters in strings Geelong_crazy 1 301 Jul-18-2020, 06:58 PM
Last Post: DT2000
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 382 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  counting characters in an object Skaperen 11 953 Jun-09-2020, 09:22 PM
Last Post: Gribouillis
  How to find the first and last of one of several characters in a list of strings? tadsss 2 386 Jun-02-2020, 05:23 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020