Transform JSON by Replacing Double Quotes with Single Quotes and Reordering Key-Value Pairs

When it comes to strings, they are enclosed within quotes. However, if the string itself contains a single quote, using single quotes to enclose it is not possible. This is because if the string starts with a single quote, it will end at the first occurrence of a single quote. As a result, the object remains unaware of whether the strings are defined with single or double quotes.


Solution:

When discussing a string, it is enclosed within quotes. However, if the string itself contains a single quote, it cannot be enclosed using single quotes. This is because the string will end at the first single quote, if it starts with one.

yathartha = "But it didn't happen"
string_var = "%r" %yathartha 
print string_var

In case the string was wrapped in single quotes, the closing quote encountered would be interpreted as the end of the string. Therefore, the string stored in string_var wouldn’t be ‘But it didn’t’.

Frequently Asked Questions