Created
February 23, 2016 20:19
-
-
Save datamafia/e45c24eb8e1f73d18edc to your computer and use it in GitHub Desktop.
Shopify API helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prepare_for_api(str_json): | |
""" | |
Prepare a json string API use by escaping double quotes and removing \n new line breaks | |
:param str_json: string | |
:return: string | |
Note: Use pattern is to wrap data at the last possible moment to avoid extra escaping. | |
""" | |
str_json = re.sub(' +', ' ', str_json) # kills multi whitespace | |
str_json = str_json.replace('\n', '') # kill new line breaks caused by triple quoted raw strings | |
str_json = str_json.replace('"', '\\"') # address double quotes | |
# Should be json ready. If not, add more. | |
return str_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment