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
#1
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?
Reply


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
  Copy xml content from webpage and save to locally without special characters Nik1811 14 616 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  remove gilberishs from a "string" kucingkembar 2 203 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  sort search results by similarity of characters jacksfrustration 5 367 Feb-16-2024, 11:59 PM
Last Post: deanhystad
  non-latin characters in console from clipboard Johanson 3 656 Oct-26-2023, 10:10 PM
Last Post: deanhystad
Question Special Characters read-write Prisonfeed 1 582 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  doing string split with 2 or more split characters Skaperen 22 2,322 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,430 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  use of escape character in re.sub and find WJSwan 1 877 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  How to remove patterns of characters from text aaander 4 1,084 Nov-19-2022, 03:34 PM
Last Post: snippsat
Smile please help me remove error for string.strip() jamie_01 3 1,151 Oct-14-2022, 07:48 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

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