Created
April 3, 2018 17:13
-
-
Save deveshmittal/3852529fddf327a7f51e349f61bb9464 to your computer and use it in GitHub Desktop.
Convert GTM keys and values to RC
This file contains hidden or 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
import json | |
import re | |
merge_json = open("mergedcontainers.json").read() | |
data = json.loads(merge_json) | |
dict_final_json = {} | |
dict_final_json['parameters']={} | |
for (key, value) in data.items(): | |
def convert(obj): | |
if isinstance(obj, bool): | |
return str(obj).lower() | |
if isinstance(obj, int): | |
return str(obj) | |
if isinstance(obj, float): | |
return str(obj) | |
return obj | |
dict_value = {} | |
dict_value["defaultValue"]={} | |
dict_value["defaultValue"]["value"] = convert(value) | |
value = dict_value | |
key = re.sub('[^a-zA-Z0-9_]', '', key) | |
dict_final_json['parameters'][key] = value | |
with open('remote_config.json', 'w') as outfile: | |
json.dump(dict_final_json, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment