Skip to content

Instantly share code, notes, and snippets.

@sushmithapopuri
Created June 2, 2024 11:14
Show Gist options
  • Select an option

  • Save sushmithapopuri/8013655212a8f5a8ff6b2b5281e28665 to your computer and use it in GitHub Desktop.

Select an option

Save sushmithapopuri/8013655212a8f5a8ff6b2b5281e28665 to your computer and use it in GitHub Desktop.
import json
a = json.load(open('GMSInventoryLayout.json'))
def get_keys1(d, curr_key=[]):
for k, v in d.items():
if isinstance(v, dict):
yield from get_keys1(v, curr_key + [k])
elif isinstance(v, list):
for i in v:
yield from get_keys1(i, curr_key + [k])
else:
yield '.'.join(curr_key + [k])
def getKeys(object, prev_key = None, keys = []):
if type(object) != type({}):
keys.append(prev_key)
return keys
new_keys = []
for k, v in object.items():
if prev_key != None:
new_key = "{}.{}".format(prev_key, k)
else:
new_key = k
new_keys.extend(getKeys(v, new_key, []))
return new_keys
print(type(a))
r = getKeys(a)
f = open('tags.properties','w')
rep_lit = ['.description','.type','.minLength','.maxLength','.pattern','.minimum','.maximum']
lis = set()
for item in r:
# write each item on a new line
for i in rep_lit:
if item.endswith(i):
lis.add(item.replace(i,''))
for o in r:
f.write("%s\n" % o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment