Skip to content

Instantly share code, notes, and snippets.

@deveshmittal
Created April 3, 2018 17:13
Show Gist options
  • Save deveshmittal/3852529fddf327a7f51e349f61bb9464 to your computer and use it in GitHub Desktop.
Save deveshmittal/3852529fddf327a7f51e349f61bb9464 to your computer and use it in GitHub Desktop.
Convert GTM keys and values to RC
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